@univerjs/sheets 1.1.0 → 1.2.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 +218 -140
- package/lib/es/index.js +220 -142
- package/lib/index.js +220 -142
- 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/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 +1 -1
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -11972,6 +11972,7 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
|
|
|
11972
11972
|
direction = _univerjs_core.Direction.RIGHT;
|
|
11973
11973
|
target.startColumn = source.endColumn + 1;
|
|
11974
11974
|
} else return false;
|
|
11975
|
+
this.setShowMenu(false);
|
|
11975
11976
|
this.direction = direction;
|
|
11976
11977
|
const autoFillSource = this._injector.invoke((accessor) => rangeToDiscreteRange(source, accessor, unitId, subUnitId));
|
|
11977
11978
|
const autoFillTarget = this._injector.invoke((accessor) => rangeToDiscreteRange(target, accessor, unitId, subUnitId));
|
|
@@ -12024,7 +12025,7 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
|
|
|
12024
12025
|
getAllHooks() {
|
|
12025
12026
|
return this._hooks;
|
|
12026
12027
|
}
|
|
12027
|
-
getActiveHooks() {
|
|
12028
|
+
getActiveHooks(applyType = this.applyType) {
|
|
12028
12029
|
const { source, target, unitId, subUnitId } = this.autoFillLocation || {};
|
|
12029
12030
|
if (!source || !target || !unitId || !subUnitId) return [];
|
|
12030
12031
|
const enabledHooks = this._hooks.filter((h) => {
|
|
@@ -12034,7 +12035,7 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
|
|
|
12034
12035
|
target,
|
|
12035
12036
|
unitId,
|
|
12036
12037
|
subUnitId
|
|
12037
|
-
}, this._direction,
|
|
12038
|
+
}, this._direction, applyType)) === true;
|
|
12038
12039
|
});
|
|
12039
12040
|
const onlyHooks = enabledHooks.filter((h) => h.type === "ONLY");
|
|
12040
12041
|
if (onlyHooks.length > 0) return this._getOneByPriority(onlyHooks);
|
|
@@ -12083,7 +12084,6 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
|
|
|
12083
12084
|
}
|
|
12084
12085
|
fillData(applyType) {
|
|
12085
12086
|
var _activeWorkbook$getAc;
|
|
12086
|
-
this.applyType = applyType;
|
|
12087
12087
|
const activeWorkbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
12088
12088
|
const activeUnitId = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId();
|
|
12089
12089
|
const activeSubUnitId = activeWorkbook === null || activeWorkbook === void 0 || (_activeWorkbook$getAc = activeWorkbook.getActiveSheet()) === null || _activeWorkbook$getAc === void 0 ? void 0 : _activeWorkbook$getAc.getSheetId();
|
|
@@ -12094,12 +12094,30 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
|
|
|
12094
12094
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
12095
12095
|
if (!worksheet) return false;
|
|
12096
12096
|
const direction = this.direction;
|
|
12097
|
+
const activeHooks = this.getActiveHooks(applyType);
|
|
12098
|
+
const fillCallbacks = activeHooks.map((hook) => {
|
|
12099
|
+
var _hook$onPrepareFillDa;
|
|
12100
|
+
return ((_hook$onPrepareFillDa = hook.onPrepareFillData) === null || _hook$onPrepareFillDa === void 0 ? void 0 : _hook$onPrepareFillDa.call(hook, {
|
|
12101
|
+
source,
|
|
12102
|
+
target,
|
|
12103
|
+
unitId,
|
|
12104
|
+
subUnitId
|
|
12105
|
+
}, direction, applyType)) ?? (() => {
|
|
12106
|
+
var _hook$onFillData;
|
|
12107
|
+
return (_hook$onFillData = hook.onFillData) === null || _hook$onFillData === void 0 ? void 0 : _hook$onFillData.call(hook, {
|
|
12108
|
+
source,
|
|
12109
|
+
target,
|
|
12110
|
+
unitId,
|
|
12111
|
+
subUnitId
|
|
12112
|
+
}, direction, applyType);
|
|
12113
|
+
});
|
|
12114
|
+
});
|
|
12115
|
+
this.applyType = applyType;
|
|
12097
12116
|
if (this._prevUndos.length > 0) this._prevUndos.forEach((undo) => {
|
|
12098
12117
|
this._commandService.syncExecuteCommand(undo.id, undo.params);
|
|
12099
12118
|
});
|
|
12100
12119
|
this._prevUndos = [];
|
|
12101
12120
|
const selection = _univerjs_core.Rectangle.union(discreteRangeToRange(source), discreteRangeToRange(target));
|
|
12102
|
-
const activeHooks = this.getActiveHooks();
|
|
12103
12121
|
if (unitId === activeUnitId && subUnitId === activeSubUnitId) this._commandService.syncExecuteCommand(SetSelectionsOperation.id, {
|
|
12104
12122
|
selections: [{
|
|
12105
12123
|
primary: getPrimaryForRange({
|
|
@@ -12118,14 +12136,8 @@ let AutoFillService = class AutoFillService extends _univerjs_core.Disposable {
|
|
|
12118
12136
|
});
|
|
12119
12137
|
const undos = [];
|
|
12120
12138
|
const redos = [];
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
const { undos: hookUndos, redos: hookRedos } = ((_hook$onFillData = hook.onFillData) === null || _hook$onFillData === void 0 ? void 0 : _hook$onFillData.call(hook, {
|
|
12124
|
-
source,
|
|
12125
|
-
target,
|
|
12126
|
-
unitId,
|
|
12127
|
-
subUnitId
|
|
12128
|
-
}, direction, applyType)) || {};
|
|
12139
|
+
fillCallbacks.forEach((fill) => {
|
|
12140
|
+
const { undos: hookUndos, redos: hookRedos } = fill() || {};
|
|
12129
12141
|
if (hookUndos) undos.push(...hookUndos);
|
|
12130
12142
|
if (hookRedos) redos.push(...hookRedos);
|
|
12131
12143
|
});
|
|
@@ -17473,8 +17485,9 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
|
|
|
17473
17485
|
onBeforeFillData: (location, direction) => {
|
|
17474
17486
|
return this._presetAndCacheData(location, direction);
|
|
17475
17487
|
},
|
|
17476
|
-
|
|
17477
|
-
|
|
17488
|
+
onPrepareFillData: (location, direction, applyType) => {
|
|
17489
|
+
const prepared = this._prepareFillData(location, direction, applyType);
|
|
17490
|
+
return () => this._fillData(location, direction, applyType, prepared);
|
|
17478
17491
|
}
|
|
17479
17492
|
}));
|
|
17480
17493
|
}
|
|
@@ -17523,7 +17536,7 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
|
|
|
17523
17536
|
const arrData = this._applyFunctions(copySquad, len, direction, applyType, customApplyFunctions, copyDataPiece, location);
|
|
17524
17537
|
const arrIndex = getDataIndex(csLen, asLen, copySquad.index);
|
|
17525
17538
|
applyDataInTypes[type].push({
|
|
17526
|
-
data: arrData,
|
|
17539
|
+
data: arrData ?? [],
|
|
17527
17540
|
index: arrIndex
|
|
17528
17541
|
});
|
|
17529
17542
|
});
|
|
@@ -17682,28 +17695,9 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
|
|
|
17682
17695
|
}
|
|
17683
17696
|
return applyMergeRanges;
|
|
17684
17697
|
}
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
const
|
|
17688
|
-
const redos = [];
|
|
17689
|
-
let hasStyle = true;
|
|
17690
|
-
if (applyType === "NO_FORMAT") {
|
|
17691
|
-
hasStyle = false;
|
|
17692
|
-
applyType = "SERIES";
|
|
17693
|
-
}
|
|
17694
|
-
const { source, target, unitId, subUnitId } = location;
|
|
17695
|
-
if (!source || !target || direction == null) return {
|
|
17696
|
-
undos,
|
|
17697
|
-
redos
|
|
17698
|
-
};
|
|
17699
|
-
const sourceRange = discreteRangeToRange(source);
|
|
17700
|
-
const targetRange = discreteRangeToRange(target);
|
|
17701
|
-
const { cols: targetCols, rows: targetRows } = target;
|
|
17702
|
-
const { cols: sourceCols, rows: sourceRows } = source;
|
|
17703
|
-
const copyData = this._copyData;
|
|
17704
|
-
let csLen;
|
|
17705
|
-
if (direction === _univerjs_core.Direction.DOWN || direction === _univerjs_core.Direction.UP) csLen = sourceRows.length;
|
|
17706
|
-
else csLen = sourceCols.length;
|
|
17698
|
+
_getFillCells(location, direction, applyType, hasStyle, csLen) {
|
|
17699
|
+
const { rows: targetRows, cols: targetCols } = location.target;
|
|
17700
|
+
const copyData = _univerjs_core.Tools.deepClone(this._copyData);
|
|
17707
17701
|
const applyDatas = [];
|
|
17708
17702
|
if (direction === _univerjs_core.Direction.DOWN || direction === _univerjs_core.Direction.UP) {
|
|
17709
17703
|
const asLen = targetRows.length;
|
|
@@ -17734,20 +17728,26 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
|
|
|
17734
17728
|
applyDatas.push(row);
|
|
17735
17729
|
});
|
|
17736
17730
|
}
|
|
17737
|
-
|
|
17731
|
+
return applyDatas;
|
|
17732
|
+
}
|
|
17733
|
+
_prepareFillData(location, direction, applyType) {
|
|
17734
|
+
var _this$_univerInstance4;
|
|
17735
|
+
const hasStyle = applyType !== "NO_FORMAT";
|
|
17736
|
+
const effectiveApplyType = hasStyle ? applyType : "SERIES";
|
|
17737
|
+
const { source, target, unitId } = location;
|
|
17738
|
+
const sourceRange = discreteRangeToRange(source);
|
|
17739
|
+
const targetRange = discreteRangeToRange(target);
|
|
17740
|
+
const { cols: targetCols, rows: targetRows } = target;
|
|
17741
|
+
const { cols: sourceCols, rows: sourceRows } = source;
|
|
17742
|
+
let csLen;
|
|
17743
|
+
if (direction === _univerjs_core.Direction.DOWN || direction === _univerjs_core.Direction.UP) csLen = sourceRows.length;
|
|
17744
|
+
else csLen = sourceCols.length;
|
|
17745
|
+
const applyDatas = this._getFillCells(location, direction, effectiveApplyType, hasStyle, csLen);
|
|
17746
|
+
const applyMergeRanges = hasStyle ? this._getMergeApplyData(sourceRange, targetRange, direction, csLen, location) : [];
|
|
17738
17747
|
const style = (_this$_univerInstance4 = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance4 === void 0 ? void 0 : _this$_univerInstance4.getStyles();
|
|
17739
|
-
|
|
17740
|
-
applyMergeRanges = this._getMergeApplyData(sourceRange, targetRange, direction, csLen, location);
|
|
17741
|
-
applyDatas.forEach((row) => {
|
|
17742
|
-
row.forEach((cellData) => {
|
|
17743
|
-
if (cellData && style) {
|
|
17744
|
-
if (style) cellData.s = style.getStyleByCell(cellData);
|
|
17745
|
-
}
|
|
17746
|
-
});
|
|
17747
|
-
});
|
|
17748
|
-
} else applyDatas.forEach((row, rowIndex) => {
|
|
17748
|
+
applyDatas.forEach((row, rowIndex) => {
|
|
17749
17749
|
row.forEach((cellData, colIndex) => {
|
|
17750
|
-
if (cellData && style) cellData.s = style.getStyleByCell(this._beforeApplyData[rowIndex][colIndex]) || null;
|
|
17750
|
+
if (cellData && style) cellData.s = hasStyle ? style.getStyleByCell(cellData) : style.getStyleByCell(this._beforeApplyData[rowIndex][colIndex]) || null;
|
|
17751
17751
|
});
|
|
17752
17752
|
});
|
|
17753
17753
|
if (applyType === "ONLY_FORMAT") applyDatas.forEach((row, rowIndex) => {
|
|
@@ -17763,30 +17763,59 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
|
|
|
17763
17763
|
}
|
|
17764
17764
|
});
|
|
17765
17765
|
});
|
|
17766
|
-
|
|
17767
|
-
|
|
17768
|
-
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
|
|
17766
|
+
const cellValue = new _univerjs_core.ObjectMatrix();
|
|
17767
|
+
targetRows.forEach((row, rowIndex) => {
|
|
17768
|
+
targetCols.forEach((col, colIndex) => {
|
|
17769
|
+
const cell = applyDatas[rowIndex][colIndex];
|
|
17770
|
+
if (cell) cellValue.setValue(row, col, cell);
|
|
17771
|
+
});
|
|
17772
|
+
});
|
|
17773
|
+
const cellValueMatrix = cellValue.getMatrix();
|
|
17774
|
+
this._autoFillService.getActiveHooks(applyType).forEach((hook) => {
|
|
17775
|
+
var _hook$onValidateFillD;
|
|
17776
|
+
(_hook$onValidateFillD = hook.onValidateFillData) === null || _hook$onValidateFillD === void 0 || _hook$onValidateFillD.call(hook, location, direction, applyType, cellValueMatrix);
|
|
17777
|
+
});
|
|
17778
|
+
return {
|
|
17779
|
+
cellValue: cellValueMatrix,
|
|
17780
|
+
applyMergeRanges,
|
|
17781
|
+
hasStyle
|
|
17782
|
+
};
|
|
17783
|
+
}
|
|
17784
|
+
_getRemoveMergeMutations(location) {
|
|
17785
|
+
var _this$_univerInstance5;
|
|
17786
|
+
const { unitId, subUnitId, target } = location;
|
|
17787
|
+
const targetRange = discreteRangeToRange(target);
|
|
17788
|
+
const undos = [];
|
|
17789
|
+
const redos = [];
|
|
17790
|
+
const deleteMergeRanges = ((_this$_univerInstance5 = this._univerInstanceService.getUnit(unitId, _univerjs_core.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) => _univerjs_core.Rectangle.intersects(merge, targetRange))) ?? [];
|
|
17791
|
+
if (deleteMergeRanges.length) {
|
|
17792
|
+
const removeMergeMutationParams = {
|
|
17793
|
+
unitId,
|
|
17794
|
+
subUnitId,
|
|
17795
|
+
ranges: deleteMergeRanges
|
|
17796
|
+
};
|
|
17797
|
+
const undoRemoveMergeMutationParams = this._injector.invoke(RemoveMergeUndoMutationFactory, removeMergeMutationParams);
|
|
17798
|
+
redos.push({
|
|
17799
|
+
id: RemoveWorksheetMergeMutation.id,
|
|
17800
|
+
params: removeMergeMutationParams
|
|
17801
|
+
});
|
|
17802
|
+
undos.unshift({
|
|
17803
|
+
id: AddWorksheetMergeMutation.id,
|
|
17804
|
+
params: undoRemoveMergeMutationParams
|
|
17772
17805
|
});
|
|
17773
|
-
if (deleteMergeRanges.length) {
|
|
17774
|
-
const removeMergeMutationParams = {
|
|
17775
|
-
unitId,
|
|
17776
|
-
subUnitId,
|
|
17777
|
-
ranges: deleteMergeRanges
|
|
17778
|
-
};
|
|
17779
|
-
const undoRemoveMergeMutationParams = this._injector.invoke(RemoveMergeUndoMutationFactory, removeMergeMutationParams);
|
|
17780
|
-
redos.push({
|
|
17781
|
-
id: RemoveWorksheetMergeMutation.id,
|
|
17782
|
-
params: removeMergeMutationParams
|
|
17783
|
-
});
|
|
17784
|
-
undos.unshift({
|
|
17785
|
-
id: AddWorksheetMergeMutation.id,
|
|
17786
|
-
params: undoRemoveMergeMutationParams
|
|
17787
|
-
});
|
|
17788
|
-
}
|
|
17789
17806
|
}
|
|
17807
|
+
return {
|
|
17808
|
+
undos,
|
|
17809
|
+
redos
|
|
17810
|
+
};
|
|
17811
|
+
}
|
|
17812
|
+
_fillData(location, direction, applyType, prepared) {
|
|
17813
|
+
const { target, unitId, subUnitId } = location;
|
|
17814
|
+
const { cellValue, applyMergeRanges, hasStyle } = prepared;
|
|
17815
|
+
const { undos, redos } = hasStyle ? this._getRemoveMergeMutations(location) : {
|
|
17816
|
+
undos: [],
|
|
17817
|
+
redos: []
|
|
17818
|
+
};
|
|
17790
17819
|
const clearMutationParams = {
|
|
17791
17820
|
subUnitId,
|
|
17792
17821
|
unitId,
|
|
@@ -17801,22 +17830,15 @@ let AutoFillController = class AutoFillController extends _univerjs_core.Disposa
|
|
|
17801
17830
|
id: SetRangeValuesMutation.id,
|
|
17802
17831
|
params: undoClearMutationParams
|
|
17803
17832
|
});
|
|
17804
|
-
const cellValue = new _univerjs_core.ObjectMatrix();
|
|
17805
|
-
targetRows.forEach((row, rowIndex) => {
|
|
17806
|
-
targetCols.forEach((col, colIndex) => {
|
|
17807
|
-
if (applyDatas[rowIndex][colIndex]) cellValue.setValue(row, col, applyDatas[rowIndex][colIndex]);
|
|
17808
|
-
});
|
|
17809
|
-
});
|
|
17810
|
-
const cellValueMatrix = cellValue.getMatrix();
|
|
17811
17833
|
const setRangeValuesMutationParams = {
|
|
17812
17834
|
subUnitId,
|
|
17813
17835
|
unitId,
|
|
17814
|
-
cellValue
|
|
17836
|
+
cellValue
|
|
17815
17837
|
};
|
|
17816
17838
|
const undoSetRangeValuesMutationParams = this._injector.invoke(SetRangeValuesUndoMutationFactory, setRangeValuesMutationParams);
|
|
17817
|
-
this._autoFillService.getActiveHooks().forEach((hook) => {
|
|
17839
|
+
this._autoFillService.getActiveHooks(applyType).forEach((hook) => {
|
|
17818
17840
|
var _hook$onBeforeSubmit;
|
|
17819
|
-
(_hook$onBeforeSubmit = hook.onBeforeSubmit) === null || _hook$onBeforeSubmit === void 0 || _hook$onBeforeSubmit.call(hook, location, direction, applyType,
|
|
17841
|
+
(_hook$onBeforeSubmit = hook.onBeforeSubmit) === null || _hook$onBeforeSubmit === void 0 || _hook$onBeforeSubmit.call(hook, location, direction, applyType, cellValue);
|
|
17820
17842
|
});
|
|
17821
17843
|
undos.unshift({
|
|
17822
17844
|
id: SetRangeValuesMutation.id,
|
|
@@ -18173,7 +18195,7 @@ SheetsFreezeSyncController = __decorate([
|
|
|
18173
18195
|
//#endregion
|
|
18174
18196
|
//#region src/controllers/permission/sheet-permission-check.controller.ts
|
|
18175
18197
|
let SheetPermissionCheckController = class SheetPermissionCheckController extends _univerjs_core.Disposable {
|
|
18176
|
-
constructor(_commandService, _univerInstanceService, _permissionService, _selectionManagerService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _localeService, _lexerTreeBuilder, _definedNamesService) {
|
|
18198
|
+
constructor(_commandService, _univerInstanceService, _permissionService, _selectionManagerService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _localeService, _lexerTreeBuilder, _definedNamesService, _autoFillService, _formulaDataModel, _functionService) {
|
|
18177
18199
|
super();
|
|
18178
18200
|
this._commandService = _commandService;
|
|
18179
18201
|
this._univerInstanceService = _univerInstanceService;
|
|
@@ -18184,6 +18206,9 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18184
18206
|
this._localeService = _localeService;
|
|
18185
18207
|
this._lexerTreeBuilder = _lexerTreeBuilder;
|
|
18186
18208
|
this._definedNamesService = _definedNamesService;
|
|
18209
|
+
this._autoFillService = _autoFillService;
|
|
18210
|
+
this._formulaDataModel = _formulaDataModel;
|
|
18211
|
+
this._functionService = _functionService;
|
|
18187
18212
|
_defineProperty(this, "disposableCollection", new _univerjs_core.DisposableCollection());
|
|
18188
18213
|
_defineProperty(this, "_triggerPermissionUIEvent$", new rxjs.Subject());
|
|
18189
18214
|
_defineProperty(this, "triggerPermissionUIEvent$", this._triggerPermissionUIEvent$.asObservable());
|
|
@@ -18191,6 +18216,29 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18191
18216
|
}
|
|
18192
18217
|
_initialize() {
|
|
18193
18218
|
this._commandExecutedListener();
|
|
18219
|
+
this.disposeWithMe(this._autoFillService.addHook({
|
|
18220
|
+
id: "permission-check",
|
|
18221
|
+
onValidateFillData: ({ unitId, subUnitId }, _direction, applyType, cellValue) => {
|
|
18222
|
+
if (applyType === "ONLY_FORMAT") return;
|
|
18223
|
+
const formulas = new _univerjs_core.ObjectMatrix(this._formulaDataModel.updateFormulaData(unitId, subUnitId, cellValue));
|
|
18224
|
+
new _univerjs_core.ObjectMatrix(cellValue).forValue((row, column) => {
|
|
18225
|
+
const formula = formulas.getValue(row, column);
|
|
18226
|
+
if (!(formula === null || formula === void 0 ? void 0 : formula.f)) return;
|
|
18227
|
+
const formulaString = this._lexerTreeBuilder.moveFormulaRefOffset(formula.f, formula.x ?? 0, formula.y ?? 0);
|
|
18228
|
+
if (!this._permissionCheckWithFormula({
|
|
18229
|
+
unitId,
|
|
18230
|
+
subUnitId,
|
|
18231
|
+
range: {
|
|
18232
|
+
startRow: row,
|
|
18233
|
+
endRow: row,
|
|
18234
|
+
startColumn: column,
|
|
18235
|
+
endColumn: column
|
|
18236
|
+
},
|
|
18237
|
+
value: { f: formulaString }
|
|
18238
|
+
})) this.blockExecuteWithoutPermission(this._localeService.t("sheets.permission.dialog.formulaErr"));
|
|
18239
|
+
});
|
|
18240
|
+
}
|
|
18241
|
+
}));
|
|
18194
18242
|
}
|
|
18195
18243
|
_commandExecutedListener() {
|
|
18196
18244
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((commandInfo) => {
|
|
@@ -18515,61 +18563,18 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18515
18563
|
_permissionCheckWithFormula(params) {
|
|
18516
18564
|
const target = getSheetCommandTarget(this._univerInstanceService, params);
|
|
18517
18565
|
if (!target) return false;
|
|
18518
|
-
const {
|
|
18566
|
+
const { unitId, subUnitId } = target;
|
|
18519
18567
|
const formulaString = params.value.f;
|
|
18520
18568
|
if (formulaString) {
|
|
18521
|
-
|
|
18522
|
-
const
|
|
18523
|
-
|
|
18524
|
-
|
|
18525
|
-
|
|
18526
|
-
|
|
18527
|
-
|
|
18528
|
-
|
|
18529
|
-
|
|
18530
|
-
if (sheetName) {
|
|
18531
|
-
const targetSheet = workbook.getSheetBySheetName(sheetName);
|
|
18532
|
-
if (!targetSheet) return true;
|
|
18533
|
-
const { startRow, endRow, startColumn, endColumn } = range;
|
|
18534
|
-
for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
|
|
18535
|
-
var _cell$selectionProtec2;
|
|
18536
|
-
const cell = targetSheet.getCell(r, c);
|
|
18537
|
-
const permission = cell === null || cell === void 0 || (_cell$selectionProtec2 = cell.selectionProtection) === null || _cell$selectionProtec2 === void 0 ? void 0 : _cell$selectionProtec2[0];
|
|
18538
|
-
if ((permission === null || permission === void 0 ? void 0 : permission[_univerjs_protocol.UnitAction.View]) === false) return false;
|
|
18539
|
-
}
|
|
18540
|
-
}
|
|
18541
|
-
}
|
|
18542
|
-
return true;
|
|
18543
|
-
} else {
|
|
18544
|
-
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
|
|
18545
|
-
if (!sequenceNodes) return true;
|
|
18546
|
-
for (let i = 0; i < sequenceNodes.length; i++) {
|
|
18547
|
-
const node = sequenceNodes[i];
|
|
18548
|
-
if (typeof node === "string" || node.nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE) continue;
|
|
18549
|
-
const { token } = node;
|
|
18550
|
-
const { unitId: sequenceGridUnitId, sheetName, range } = (0, _univerjs_engine_formula.deserializeRangeWithSheetWithCache)(token);
|
|
18551
|
-
let sequenceGridWorkbook = workbook;
|
|
18552
|
-
if (sequenceGridUnitId && sequenceGridUnitId !== unitId) {
|
|
18553
|
-
const _sequenceGridWorkbook = this._univerInstanceService.getUnit(sequenceGridUnitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
18554
|
-
if (!_sequenceGridWorkbook) return true;
|
|
18555
|
-
sequenceGridWorkbook = _sequenceGridWorkbook;
|
|
18556
|
-
}
|
|
18557
|
-
const sequenceGridWorksheet = sheetName ? sequenceGridWorkbook.getSheetBySheetName(sheetName) : sequenceGridWorkbook.getActiveSheet();
|
|
18558
|
-
if (!sequenceGridWorksheet) return true;
|
|
18559
|
-
if (sheetName) {
|
|
18560
|
-
const viewPermission = this._permissionService.getPermissionPoint(new WorksheetViewPermission(sequenceGridWorkbook.getUnitId(), sequenceGridWorksheet.getSheetId()).id);
|
|
18561
|
-
if (!viewPermission || viewPermission.value === false) return false;
|
|
18562
|
-
}
|
|
18563
|
-
const { startRow, endRow, startColumn, endColumn } = range;
|
|
18564
|
-
for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
|
|
18565
|
-
var _cell$selectionProtec3;
|
|
18566
|
-
const cell = sequenceGridWorksheet.getCell(r, c);
|
|
18567
|
-
const permission = cell === null || cell === void 0 || (_cell$selectionProtec3 = cell.selectionProtection) === null || _cell$selectionProtec3 === void 0 ? void 0 : _cell$selectionProtec3[0];
|
|
18568
|
-
if ((permission === null || permission === void 0 ? void 0 : permission[_univerjs_protocol.UnitAction.View]) === false) return false;
|
|
18569
|
-
}
|
|
18570
|
-
}
|
|
18571
|
-
return true;
|
|
18572
|
-
}
|
|
18569
|
+
var _this$_selectionManag3;
|
|
18570
|
+
const ranges = params.range ? [params.range] : ((_this$_selectionManag3 = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag3 === void 0 ? void 0 : _this$_selectionManag3.map((selection) => selection.range)) ?? [];
|
|
18571
|
+
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, {
|
|
18572
|
+
unitId,
|
|
18573
|
+
subUnitId,
|
|
18574
|
+
row,
|
|
18575
|
+
column
|
|
18576
|
+
})) return false;
|
|
18577
|
+
return true;
|
|
18573
18578
|
}
|
|
18574
18579
|
const { range } = params;
|
|
18575
18580
|
if (range) {
|
|
@@ -18580,6 +18585,73 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18580
18585
|
}
|
|
18581
18586
|
return true;
|
|
18582
18587
|
}
|
|
18588
|
+
_getFormulaReferenceWorkbook(unitId, qualifier) {
|
|
18589
|
+
const workbook = this._univerInstanceService.getUnit(qualifier || unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
18590
|
+
if (workbook || !qualifier) return workbook;
|
|
18591
|
+
const workbooks = this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).filter((item) => item.getSnapshot().name.length > 0);
|
|
18592
|
+
const exactMatches = workbooks.filter((item) => item.getSnapshot().name.toLowerCase() === qualifier.toLowerCase());
|
|
18593
|
+
const matches = exactMatches.length > 0 ? exactMatches : workbooks.filter((item) => (0, _univerjs_engine_formula.normalizeFormulaUnitName)(item.getSnapshot().name) === (0, _univerjs_engine_formula.normalizeFormulaUnitName)(qualifier));
|
|
18594
|
+
return matches.length === 1 ? matches[0] : null;
|
|
18595
|
+
}
|
|
18596
|
+
_permissionCheckFormulaReferences(formulaString, context, visitingNames = /* @__PURE__ */ new Set(), referenceOffset) {
|
|
18597
|
+
const { unitId, subUnitId, row, column } = context;
|
|
18598
|
+
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString) ?? [];
|
|
18599
|
+
for (let index = 0; index < sequenceNodes.length; index++) {
|
|
18600
|
+
const node = sequenceNodes[index];
|
|
18601
|
+
if (typeof node === "string" || node.nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE && node.nodeType !== _univerjs_engine_formula.sequenceNodeType.FUNCTION) continue;
|
|
18602
|
+
const nextNode = sequenceNodes[index + 1];
|
|
18603
|
+
if (node.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION && typeof nextNode === "string" && nextNode.trim() === _univerjs_engine_formula.matchToken.OPEN_BRACKET && this._functionService.hasExecutor(node.token.trim().toUpperCase())) continue;
|
|
18604
|
+
let nameToken = node.token.trim();
|
|
18605
|
+
if (node.nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION) {
|
|
18606
|
+
const parts = nameToken.split("!");
|
|
18607
|
+
if (parts.length === 2) {
|
|
18608
|
+
var _this$_univerInstance;
|
|
18609
|
+
const unqualifiedName = parts[1].trim();
|
|
18610
|
+
const unscopedName = this._definedNamesService.getValueByName(unitId, unqualifiedName);
|
|
18611
|
+
const localSheetId = unscopedName === null || unscopedName === void 0 ? void 0 : unscopedName.localSheetId;
|
|
18612
|
+
const localSheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(localSheetId ?? "");
|
|
18613
|
+
if (unscopedName && (localSheetId == null || localSheetId === "AllDefaultWorkbook" || (localSheet === null || localSheet === void 0 ? void 0 : localSheet.getName()) === parts[0])) nameToken = unqualifiedName;
|
|
18614
|
+
}
|
|
18615
|
+
}
|
|
18616
|
+
const definedName = this._definedNamesService.getValueByName(unitId, nameToken, subUnitId);
|
|
18617
|
+
if (definedName) {
|
|
18618
|
+
const nameKey = `${unitId}:${definedName.id}`;
|
|
18619
|
+
if (visitingNames.has(nameKey)) continue;
|
|
18620
|
+
visitingNames.add(nameKey);
|
|
18621
|
+
const definition = definedName.formulaOrRefString;
|
|
18622
|
+
const isFormula = definition.startsWith(_univerjs_engine_formula.operatorToken.EQUALS);
|
|
18623
|
+
const offset = isFormula ? void 0 : {
|
|
18624
|
+
x: column - (definedName.localSheetId === "AllDefaultWorkbook" ? 1 : 0),
|
|
18625
|
+
y: row
|
|
18626
|
+
};
|
|
18627
|
+
const permitted = this._permissionCheckFormulaReferences(isFormula ? definition : `${_univerjs_engine_formula.operatorToken.EQUALS}${definition}`, context, visitingNames, offset);
|
|
18628
|
+
visitingNames.delete(nameKey);
|
|
18629
|
+
if (!permitted) return false;
|
|
18630
|
+
continue;
|
|
18631
|
+
}
|
|
18632
|
+
if (node.nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE) continue;
|
|
18633
|
+
const { unitQualifier, sheetName } = (0, _univerjs_engine_formula.handleRefStringInfo)(node.token.trim());
|
|
18634
|
+
const referenceWorkbook = this._getFormulaReferenceWorkbook(unitId, unitQualifier);
|
|
18635
|
+
const referenceWorksheet = sheetName ? referenceWorkbook === null || referenceWorkbook === void 0 ? void 0 : referenceWorkbook.getSheetBySheetName(sheetName) : referenceWorkbook === null || referenceWorkbook === void 0 ? void 0 : referenceWorkbook.getSheetBySheetId(subUnitId);
|
|
18636
|
+
if (!referenceWorkbook || !referenceWorksheet) continue;
|
|
18637
|
+
const referenceUnitId = referenceWorkbook.getUnitId();
|
|
18638
|
+
const referenceSheetId = referenceWorksheet.getSheetId();
|
|
18639
|
+
const { range } = (0, _univerjs_engine_formula.deserializeRangeWithSheetWithCache)(node.token);
|
|
18640
|
+
const referenceRange = referenceOffset ? (0, _univerjs_core.moveRangeByOffset)({ ...range }, referenceOffset.x, referenceOffset.y) : range;
|
|
18641
|
+
if (referenceOffset) {
|
|
18642
|
+
const wrap = (value, limit) => (value % limit + limit) % limit;
|
|
18643
|
+
referenceRange.startRow = wrap(referenceRange.startRow, _univerjs_core.MAX_ROW_COUNT);
|
|
18644
|
+
referenceRange.endRow = wrap(referenceRange.endRow, _univerjs_core.MAX_ROW_COUNT);
|
|
18645
|
+
referenceRange.startColumn = wrap(referenceRange.startColumn, _univerjs_core.MAX_COLUMN_COUNT);
|
|
18646
|
+
referenceRange.endColumn = wrap(referenceRange.endColumn, _univerjs_core.MAX_COLUMN_COUNT);
|
|
18647
|
+
}
|
|
18648
|
+
if (!this.permissionCheckWithRanges({
|
|
18649
|
+
worksheetTypes: [WorksheetViewPermission],
|
|
18650
|
+
rangeTypes: [RangeProtectionPermissionViewPoint]
|
|
18651
|
+
}, [referenceRange], referenceUnitId, referenceSheetId)) return false;
|
|
18652
|
+
}
|
|
18653
|
+
return true;
|
|
18654
|
+
}
|
|
18583
18655
|
_permissionCheckBySetRangeValue(permissionTypes, params) {
|
|
18584
18656
|
const { unitId, subUnitId, value, range } = params;
|
|
18585
18657
|
let ranges = [];
|
|
@@ -18675,11 +18747,11 @@ let SheetPermissionCheckController = class SheetPermissionCheckController extend
|
|
|
18675
18747
|
return true;
|
|
18676
18748
|
}
|
|
18677
18749
|
_permissionCheckWithInsertOrDeleteMoveRange(direction, params) {
|
|
18678
|
-
var _this$
|
|
18750
|
+
var _this$_selectionManag4;
|
|
18679
18751
|
const target = getSheetCommandTarget(this._univerInstanceService);
|
|
18680
18752
|
if (!target) return false;
|
|
18681
18753
|
const { worksheet, unitId, subUnitId } = target;
|
|
18682
|
-
const range = (params === null || params === void 0 ? void 0 : params.range) ?? ((_this$
|
|
18754
|
+
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);
|
|
18683
18755
|
if (!range) return false;
|
|
18684
18756
|
if (!this.permissionCheckWithRanges({
|
|
18685
18757
|
workbookTypes: [WorkbookEditablePermission],
|
|
@@ -18704,7 +18776,10 @@ SheetPermissionCheckController = __decorate([
|
|
|
18704
18776
|
__decorateParam(5, (0, _univerjs_core.Inject)(WorksheetProtectionRuleModel)),
|
|
18705
18777
|
__decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
18706
18778
|
__decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder)),
|
|
18707
|
-
__decorateParam(8, _univerjs_engine_formula.IDefinedNamesService)
|
|
18779
|
+
__decorateParam(8, _univerjs_engine_formula.IDefinedNamesService),
|
|
18780
|
+
__decorateParam(9, IAutoFillService),
|
|
18781
|
+
__decorateParam(10, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
|
|
18782
|
+
__decorateParam(11, _univerjs_engine_formula.IFunctionService)
|
|
18708
18783
|
], SheetPermissionCheckController);
|
|
18709
18784
|
|
|
18710
18785
|
//#endregion
|
|
@@ -19570,7 +19645,7 @@ RangeProtectionCache = __decorate([
|
|
|
19570
19645
|
//#endregion
|
|
19571
19646
|
//#region package.json
|
|
19572
19647
|
var name = "@univerjs/sheets";
|
|
19573
|
-
var version = "1.
|
|
19648
|
+
var version = "1.2.0";
|
|
19574
19649
|
|
|
19575
19650
|
//#endregion
|
|
19576
19651
|
//#region src/controllers/active-worksheet.controller.ts
|
|
@@ -21500,7 +21575,10 @@ function convertPositionCellToSheetOverGrid(unitId, subUnitId, cellOverGridPosit
|
|
|
21500
21575
|
});
|
|
21501
21576
|
const left = (0, _univerjs_engine_render.precisionTo)(startSelectionX + fromColumnOffset, 1);
|
|
21502
21577
|
const top = (0, _univerjs_engine_render.precisionTo)(startSelectionY + fromRowOffset, 1);
|
|
21503
|
-
const endSelectionCell = skeleton.getCellIndexAndOffsetByPosition(left + width, top + height
|
|
21578
|
+
const endSelectionCell = skeleton.getCellIndexAndOffsetByPosition(left + width, top + height, 1, 1, {
|
|
21579
|
+
x: 0,
|
|
21580
|
+
y: 0
|
|
21581
|
+
});
|
|
21504
21582
|
return {
|
|
21505
21583
|
unitId,
|
|
21506
21584
|
subUnitId,
|