@univerjs/sheets-data-validation 0.5.4 → 0.5.5-experimental.20250122-3362a4a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +690 -445
- package/lib/es/index.js +1741 -1702
- package/lib/types/facade/f-data-validation-builder.d.ts +238 -133
- package/lib/types/facade/f-data-validation.d.ts +158 -38
- package/lib/types/facade/f-range.d.ts +36 -9
- package/lib/types/facade/f-univer.d.ts +13 -1
- package/lib/types/facade/f-workbook.d.ts +8 -24
- package/lib/types/facade/f-worksheet.d.ts +9 -4
- package/lib/types/services/dv-validator-service.d.ts +1 -1
- package/lib/types/validators/custom-validator.d.ts +1 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
- package/LICENSE +0 -176
package/lib/es/index.js
CHANGED
|
@@ -1,448 +1,455 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { Inject, ICommandService, IUniverInstanceService, Disposable, ObjectMatrix, UniverInstanceType, Range, isFormulaString, DataValidationType, getOriginCellValue, RBush, debounce, Rectangle, Tools, DataValidationStatus, WrapStrategy, DataValidationOperator, numfmt, dayjs, DataValidationRenderMode, CommandType, IUndoRedoService, sequenceExecute, isRangesEqual, generateRandomId, toDisposable, IPermissionService, Injector, CellValueType, RxDisposable, LifecycleService, LifecycleStages, bufferDebounceTime, DependentOn, Plugin, merge, IConfigService } from "@univerjs/core";
|
|
6
|
+
import { DataValidationModel, DataValidatorRegistryService, UpdateRuleType, BaseDataValidator, TextLengthErrorTitleMap, AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation, getRuleSetting, getRuleOptions, UniverDataValidationPlugin } from "@univerjs/data-validation";
|
|
7
|
+
import { SetRangeValuesMutation, RemoveSheetMutation, getSheetCommandTarget, SetRangeValuesUndoMutationFactory, WorksheetViewPermission, RefRangeService, handleCommonDefaultRangeChangeWithEffectRefCommands, SheetInterceptorService, RemoveSheetCommand, SheetsSelectionsService, ClearSelectionAllCommand } from "@univerjs/sheets";
|
|
8
|
+
import { Subject, bufferWhen, filter } from "rxjs";
|
|
9
|
+
import { RegisterOtherFormulaService, FormulaRefRangeService } from "@univerjs/sheets-formula";
|
|
10
|
+
import { ERROR_TYPE_SET, LexerTreeBuilder, isReferenceString, sequenceNodeType, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, operatorToken } from "@univerjs/engine-formula";
|
|
11
|
+
const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN";
|
|
12
|
+
var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
13
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
14
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
15
|
+
return kind && result && __defProp$a(target, key, result), result;
|
|
16
|
+
}, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a;
|
|
17
|
+
let DataValidationCacheService = (_a = class extends Disposable {
|
|
18
|
+
constructor(_commandService, _univerInstanceService) {
|
|
18
19
|
super();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this._commandService =
|
|
20
|
+
__publicField(this, "_cacheMatrix", /* @__PURE__ */ new Map());
|
|
21
|
+
__publicField(this, "_dirtyRanges$", new Subject());
|
|
22
|
+
__publicField(this, "dirtyRanges$", this._dirtyRanges$.asObservable());
|
|
23
|
+
this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._initDirtyRanges(), this._initSheetRemove();
|
|
23
24
|
}
|
|
24
25
|
_initDirtyRanges() {
|
|
25
|
-
this.disposeWithMe(this._commandService.onCommandExecuted((
|
|
26
|
-
if (
|
|
27
|
-
const { cellValue
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
this.markRangeDirty(
|
|
26
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
27
|
+
if (commandInfo.id === SetRangeValuesMutation.id) {
|
|
28
|
+
const { cellValue, unitId, subUnitId } = commandInfo.params;
|
|
29
|
+
if (cellValue) {
|
|
30
|
+
const range = new ObjectMatrix(cellValue).getDataRange();
|
|
31
|
+
if (range.endRow === -1) return;
|
|
32
|
+
this.markRangeDirty(unitId, subUnitId, [range]);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
}));
|
|
35
36
|
}
|
|
36
37
|
_initSheetRemove() {
|
|
37
|
-
this.disposeWithMe(this._commandService.onCommandExecuted((
|
|
38
|
-
var
|
|
39
|
-
if (
|
|
40
|
-
const { unitId
|
|
41
|
-
(
|
|
38
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
39
|
+
var _a12;
|
|
40
|
+
if (commandInfo.id === RemoveSheetMutation.id) {
|
|
41
|
+
const { unitId, subUnitId } = commandInfo.params;
|
|
42
|
+
(_a12 = this._cacheMatrix.get(unitId)) == null || _a12.delete(subUnitId);
|
|
42
43
|
}
|
|
43
|
-
})), this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((
|
|
44
|
-
|
|
44
|
+
})), this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((univerInstance) => {
|
|
45
|
+
univerInstance.type === UniverInstanceType.UNIVER_SHEET && this._cacheMatrix.delete(univerInstance.getUnitId());
|
|
45
46
|
}));
|
|
46
47
|
}
|
|
47
|
-
_ensureCache(
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
let
|
|
51
|
-
return
|
|
48
|
+
_ensureCache(unitId, subUnitId) {
|
|
49
|
+
let unitMap = this._cacheMatrix.get(unitId);
|
|
50
|
+
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._cacheMatrix.set(unitId, unitMap));
|
|
51
|
+
let cacheMatrix = unitMap.get(subUnitId);
|
|
52
|
+
return cacheMatrix || (cacheMatrix = new ObjectMatrix(), unitMap.set(subUnitId, cacheMatrix)), cacheMatrix;
|
|
52
53
|
}
|
|
53
|
-
ensureCache(
|
|
54
|
-
return this._ensureCache(
|
|
54
|
+
ensureCache(unitId, subUnitId) {
|
|
55
|
+
return this._ensureCache(unitId, subUnitId);
|
|
55
56
|
}
|
|
56
|
-
addRule(
|
|
57
|
-
this.markRangeDirty(
|
|
57
|
+
addRule(unitId, subUnitId, rule) {
|
|
58
|
+
this.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
58
59
|
}
|
|
59
|
-
removeRule(
|
|
60
|
-
this._deleteRange(
|
|
60
|
+
removeRule(unitId, subUnitId, rule) {
|
|
61
|
+
this._deleteRange(unitId, subUnitId, rule.ranges);
|
|
61
62
|
}
|
|
62
|
-
markRangeDirty(
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
markRangeDirty(unitId, subUnitId, ranges) {
|
|
64
|
+
const cache = this._ensureCache(unitId, subUnitId);
|
|
65
|
+
ranges.forEach((range) => {
|
|
66
|
+
Range.foreach(range, (row, col) => {
|
|
67
|
+
cache.setValue(row, col, void 0);
|
|
67
68
|
});
|
|
68
|
-
}), this._dirtyRanges$.next({ unitId
|
|
69
|
+
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
|
|
69
70
|
}
|
|
70
|
-
_deleteRange(
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
_deleteRange(unitId, subUnitId, ranges) {
|
|
72
|
+
const cache = this._ensureCache(unitId, subUnitId);
|
|
73
|
+
ranges.forEach((range) => {
|
|
74
|
+
Range.foreach(range, (row, col) => {
|
|
75
|
+
cache.realDeleteValue(row, col);
|
|
75
76
|
});
|
|
76
|
-
}), this._dirtyRanges$.next({ unitId
|
|
77
|
-
}
|
|
78
|
-
getValue(
|
|
79
|
-
return this._ensureCache(
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
],
|
|
86
|
-
function
|
|
87
|
-
var
|
|
88
|
-
return (
|
|
77
|
+
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
|
|
78
|
+
}
|
|
79
|
+
getValue(unitId, subUnitId, row, col) {
|
|
80
|
+
return this._ensureCache(unitId, subUnitId).getValue(row, col);
|
|
81
|
+
}
|
|
82
|
+
}, __name(_a, "DataValidationCacheService"), _a);
|
|
83
|
+
DataValidationCacheService = __decorateClass$a([
|
|
84
|
+
__decorateParam$a(0, Inject(ICommandService)),
|
|
85
|
+
__decorateParam$a(1, Inject(IUniverInstanceService))
|
|
86
|
+
], DataValidationCacheService);
|
|
87
|
+
function getFormulaResult(result) {
|
|
88
|
+
var _a12, _b;
|
|
89
|
+
return (_b = (_a12 = result == null ? void 0 : result[0]) == null ? void 0 : _a12[0]) == null ? void 0 : _b.v;
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
__name(getFormulaResult, "getFormulaResult");
|
|
92
|
+
function getFormulaCellData(result) {
|
|
93
|
+
var _a12;
|
|
94
|
+
return (_a12 = result == null ? void 0 : result[0]) == null ? void 0 : _a12[0];
|
|
93
95
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
__name(getFormulaCellData, "getFormulaCellData");
|
|
97
|
+
function isLegalFormulaResult(res) {
|
|
98
|
+
return !ERROR_TYPE_SET.has(res);
|
|
96
99
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
__name(isLegalFormulaResult, "isLegalFormulaResult");
|
|
101
|
+
function shouldOffsetFormulaByRange(type, validatorRegistryService) {
|
|
102
|
+
var _a12;
|
|
103
|
+
const validator = validatorRegistryService.getValidatorItem(type);
|
|
104
|
+
return (_a12 = validator == null ? void 0 : validator.offsetFormulaByRange) != null ? _a12 : !1;
|
|
101
105
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
__name(shouldOffsetFormulaByRange, "shouldOffsetFormulaByRange");
|
|
107
|
+
var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
108
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
109
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
110
|
+
return kind && result && __defProp$9(target, key, result), result;
|
|
111
|
+
}, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a2;
|
|
112
|
+
let DataValidationCustomFormulaService = (_a2 = class extends Disposable {
|
|
113
|
+
constructor(_instanceSrv, _registerOtherFormulaService, _dataValidationModel, _dataValidationCacheService, _validatorRegistryService) {
|
|
109
114
|
super();
|
|
110
115
|
/**
|
|
111
116
|
* Map of origin formula of rule
|
|
112
117
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this._instanceSrv =
|
|
118
|
+
__publicField(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
|
|
119
|
+
__publicField(this, "_ruleFormulaMap2", /* @__PURE__ */ new Map());
|
|
120
|
+
this._instanceSrv = _instanceSrv, this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationModel = _dataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._validatorRegistryService = _validatorRegistryService, this._initFormulaResultHandler();
|
|
116
121
|
}
|
|
117
122
|
_initFormulaResultHandler() {
|
|
118
|
-
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((
|
|
119
|
-
for (const
|
|
120
|
-
const
|
|
121
|
-
if (this._instanceSrv.getUnitType(
|
|
122
|
-
for (const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
var
|
|
126
|
-
const
|
|
127
|
-
|
|
123
|
+
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
124
|
+
for (const unitId in resultMap) {
|
|
125
|
+
const unitMap = resultMap[unitId];
|
|
126
|
+
if (this._instanceSrv.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
|
|
127
|
+
for (const subUnitId in unitMap) {
|
|
128
|
+
const results = unitMap[subUnitId], { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
129
|
+
results.forEach((result) => {
|
|
130
|
+
var _a12, _b;
|
|
131
|
+
const ruleInfo = ruleFormulaMap.get((_a12 = result.extra) == null ? void 0 : _a12.ruleId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
|
|
132
|
+
rule && ruleInfo && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
128
133
|
});
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
}));
|
|
132
137
|
}
|
|
133
|
-
_ensureMaps(
|
|
134
|
-
let
|
|
135
|
-
|
|
136
|
-
let
|
|
137
|
-
|
|
138
|
-
let
|
|
139
|
-
return
|
|
138
|
+
_ensureMaps(unitId, subUnitId) {
|
|
139
|
+
let ruleFormulaUnitMap = this._ruleFormulaMap.get(unitId), ruleFormulaUnitMap2 = this._ruleFormulaMap2.get(unitId);
|
|
140
|
+
ruleFormulaUnitMap || (ruleFormulaUnitMap = /* @__PURE__ */ new Map(), this._ruleFormulaMap.set(unitId, ruleFormulaUnitMap)), ruleFormulaUnitMap2 || (ruleFormulaUnitMap2 = /* @__PURE__ */ new Map(), this._ruleFormulaMap2.set(unitId, ruleFormulaUnitMap2));
|
|
141
|
+
let ruleFormulaMap = ruleFormulaUnitMap.get(subUnitId);
|
|
142
|
+
ruleFormulaMap || (ruleFormulaMap = /* @__PURE__ */ new Map(), ruleFormulaUnitMap.set(subUnitId, ruleFormulaMap));
|
|
143
|
+
let ruleFormulaMap2 = ruleFormulaUnitMap2.get(subUnitId);
|
|
144
|
+
return ruleFormulaMap2 || (ruleFormulaMap2 = /* @__PURE__ */ new Map(), ruleFormulaUnitMap2.set(subUnitId, ruleFormulaMap2)), { ruleFormulaMap, ruleFormulaMap2 };
|
|
140
145
|
}
|
|
141
|
-
_registerFormula(
|
|
142
|
-
return this._registerOtherFormulaService.registerFormulaWithRange(
|
|
146
|
+
_registerFormula(unitId, subUnitId, ruleId, formulaString, ranges) {
|
|
147
|
+
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaString, ranges, { ruleId });
|
|
143
148
|
}
|
|
144
|
-
deleteByRuleId(
|
|
145
|
-
const { ruleFormulaMap
|
|
146
|
-
if (!
|
|
149
|
+
deleteByRuleId(unitId, subUnitId, ruleId) {
|
|
150
|
+
const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId), formulaInfo = ruleFormulaMap.get(ruleId);
|
|
151
|
+
if (!rule || !formulaInfo)
|
|
147
152
|
return;
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
_addFormulaByRange(
|
|
154
|
-
const { ruleFormulaMap
|
|
155
|
-
if (
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
formula
|
|
159
|
-
originCol
|
|
160
|
-
originRow
|
|
161
|
-
formulaId
|
|
153
|
+
const current = ruleFormulaMap.get(ruleId);
|
|
154
|
+
current && (ruleFormulaMap.delete(ruleId), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [current.formulaId]));
|
|
155
|
+
const current2 = ruleFormulaMap2.get(ruleId);
|
|
156
|
+
current2 && (ruleFormulaMap2.delete(ruleId), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [current2.formulaId]));
|
|
157
|
+
}
|
|
158
|
+
_addFormulaByRange(unitId, subUnitId, ruleId, formula, formula2, ranges) {
|
|
159
|
+
const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), originRow = ranges[0].startRow, originCol = ranges[0].startColumn;
|
|
160
|
+
if (formula && isFormulaString(formula)) {
|
|
161
|
+
const formulaId = this._registerFormula(unitId, subUnitId, ruleId, formula, ranges);
|
|
162
|
+
ruleFormulaMap.set(ruleId, {
|
|
163
|
+
formula,
|
|
164
|
+
originCol,
|
|
165
|
+
originRow,
|
|
166
|
+
formulaId
|
|
162
167
|
});
|
|
163
168
|
}
|
|
164
|
-
if (
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
formula:
|
|
168
|
-
originCol
|
|
169
|
-
originRow
|
|
170
|
-
formulaId:
|
|
169
|
+
if (formula2 && isFormulaString(formula2)) {
|
|
170
|
+
const formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, formula2, ranges);
|
|
171
|
+
ruleFormulaMap2.set(ruleId, {
|
|
172
|
+
formula: formula2,
|
|
173
|
+
originCol,
|
|
174
|
+
originRow,
|
|
175
|
+
formulaId: formulaId2
|
|
171
176
|
});
|
|
172
177
|
}
|
|
173
178
|
}
|
|
174
|
-
addRule(
|
|
175
|
-
if (
|
|
176
|
-
const { ranges
|
|
177
|
-
this._addFormulaByRange(
|
|
179
|
+
addRule(unitId, subUnitId, rule) {
|
|
180
|
+
if (shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService)) {
|
|
181
|
+
const { ranges, formula1, formula2, uid: ruleId } = rule;
|
|
182
|
+
this._addFormulaByRange(unitId, subUnitId, ruleId, formula1, formula2, ranges);
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
|
-
async getCellFormulaValue(
|
|
181
|
-
var
|
|
182
|
-
const { ruleFormulaMap
|
|
183
|
-
if (!
|
|
185
|
+
async getCellFormulaValue(unitId, subUnitId, ruleId, row, column) {
|
|
186
|
+
var _a12, _b;
|
|
187
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap.get(ruleId);
|
|
188
|
+
if (!current)
|
|
184
189
|
return Promise.resolve(void 0);
|
|
185
|
-
const
|
|
186
|
-
return
|
|
190
|
+
const result = await this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
|
|
191
|
+
return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
|
|
187
192
|
}
|
|
188
|
-
async getCellFormula2Value(
|
|
189
|
-
var
|
|
190
|
-
const { ruleFormulaMap2
|
|
191
|
-
if (!
|
|
193
|
+
async getCellFormula2Value(unitId, subUnitId, ruleId, row, column) {
|
|
194
|
+
var _a12, _b;
|
|
195
|
+
const { ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap2.get(ruleId);
|
|
196
|
+
if (!current)
|
|
192
197
|
return Promise.resolve(void 0);
|
|
193
|
-
const
|
|
194
|
-
return
|
|
198
|
+
const result = await this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
|
|
199
|
+
return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
|
|
195
200
|
}
|
|
196
|
-
getCellFormulaValueSync(
|
|
197
|
-
var
|
|
198
|
-
const { ruleFormulaMap
|
|
199
|
-
if (!
|
|
201
|
+
getCellFormulaValueSync(unitId, subUnitId, ruleId, row, column) {
|
|
202
|
+
var _a12, _b;
|
|
203
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap.get(ruleId);
|
|
204
|
+
if (!current)
|
|
200
205
|
return;
|
|
201
|
-
const
|
|
202
|
-
return
|
|
206
|
+
const result = this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
|
|
207
|
+
return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
|
|
203
208
|
}
|
|
204
|
-
getCellFormula2ValueSync(
|
|
205
|
-
var
|
|
206
|
-
const { ruleFormulaMap2
|
|
207
|
-
if (!
|
|
209
|
+
getCellFormula2ValueSync(unitId, subUnitId, ruleId, row, column) {
|
|
210
|
+
var _a12, _b;
|
|
211
|
+
const { ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap2.get(ruleId);
|
|
212
|
+
if (!current)
|
|
208
213
|
return;
|
|
209
|
-
const
|
|
210
|
-
return
|
|
211
|
-
}
|
|
212
|
-
getRuleFormulaInfo(
|
|
213
|
-
const { ruleFormulaMap
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
],
|
|
224
|
-
var
|
|
225
|
-
for (var
|
|
226
|
-
(
|
|
227
|
-
return
|
|
228
|
-
},
|
|
229
|
-
let
|
|
230
|
-
constructor(
|
|
214
|
+
const result = this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
|
|
215
|
+
return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
|
|
216
|
+
}
|
|
217
|
+
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
218
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
219
|
+
return ruleFormulaMap.get(ruleId);
|
|
220
|
+
}
|
|
221
|
+
}, __name(_a2, "DataValidationCustomFormulaService"), _a2);
|
|
222
|
+
DataValidationCustomFormulaService = __decorateClass$9([
|
|
223
|
+
__decorateParam$9(0, IUniverInstanceService),
|
|
224
|
+
__decorateParam$9(1, Inject(RegisterOtherFormulaService)),
|
|
225
|
+
__decorateParam$9(2, Inject(DataValidationModel)),
|
|
226
|
+
__decorateParam$9(3, Inject(DataValidationCacheService)),
|
|
227
|
+
__decorateParam$9(4, Inject(DataValidatorRegistryService))
|
|
228
|
+
], DataValidationCustomFormulaService);
|
|
229
|
+
var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
230
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
231
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
232
|
+
return kind && result && __defProp$8(target, key, result), result;
|
|
233
|
+
}, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a3;
|
|
234
|
+
let DataValidationFormulaService = (_a3 = class extends Disposable {
|
|
235
|
+
constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel, _validatorRegistryService) {
|
|
231
236
|
super();
|
|
232
|
-
|
|
233
|
-
this._instanceService =
|
|
237
|
+
__publicField(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
|
|
238
|
+
this._instanceService = _instanceService, this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationModel = _dataValidationModel, this._validatorRegistryService = _validatorRegistryService, this._initFormulaResultHandler();
|
|
234
239
|
}
|
|
235
240
|
_initFormulaResultHandler() {
|
|
236
|
-
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((
|
|
237
|
-
for (const
|
|
238
|
-
const
|
|
239
|
-
if (this._instanceService.getUnitType(
|
|
240
|
-
for (const
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
var
|
|
244
|
-
if (
|
|
245
|
-
const
|
|
246
|
-
|
|
241
|
+
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
242
|
+
for (const unitId in resultMap) {
|
|
243
|
+
const unitMap = resultMap[unitId];
|
|
244
|
+
if (this._instanceService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
|
|
245
|
+
for (const subUnitId in unitMap) {
|
|
246
|
+
const results = unitMap[subUnitId], formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
|
|
247
|
+
results.forEach((result) => {
|
|
248
|
+
var _a12, _b;
|
|
249
|
+
if (formulaMap.get((_a12 = result.extra) == null ? void 0 : _a12.ruleId)) {
|
|
250
|
+
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
|
|
251
|
+
rule && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
247
252
|
}
|
|
248
253
|
});
|
|
249
254
|
}
|
|
250
255
|
}
|
|
251
256
|
}));
|
|
252
257
|
}
|
|
253
|
-
_ensureRuleFormulaMap(
|
|
254
|
-
let
|
|
255
|
-
|
|
256
|
-
let
|
|
257
|
-
return
|
|
258
|
+
_ensureRuleFormulaMap(unitId, subUnitId) {
|
|
259
|
+
let unitMap = this._formulaRuleMap.get(unitId);
|
|
260
|
+
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._formulaRuleMap.set(unitId, unitMap));
|
|
261
|
+
let subUnitMap = unitMap.get(subUnitId);
|
|
262
|
+
return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
|
|
258
263
|
}
|
|
259
|
-
_registerSingleFormula(
|
|
260
|
-
const
|
|
261
|
-
return this._registerOtherFormulaService.registerFormulaWithRange(
|
|
264
|
+
_registerSingleFormula(unitId, subUnitId, formula, ruleId) {
|
|
265
|
+
const ranges = [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }];
|
|
266
|
+
return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formula, ranges, { ruleId });
|
|
262
267
|
}
|
|
263
|
-
addRule(
|
|
264
|
-
if (!
|
|
265
|
-
const { formula1
|
|
266
|
-
if (!
|
|
268
|
+
addRule(unitId, subUnitId, rule) {
|
|
269
|
+
if (!shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService) && rule.type !== DataValidationType.CHECKBOX) {
|
|
270
|
+
const { formula1, formula2, uid: ruleId } = rule, isFormula1Legal = isFormulaString(formula1), isFormula2Legal = isFormulaString(formula2);
|
|
271
|
+
if (!isFormula1Legal && !isFormula2Legal)
|
|
267
272
|
return;
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
const
|
|
271
|
-
|
|
273
|
+
const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId), item = [void 0, void 0];
|
|
274
|
+
if (isFormula1Legal) {
|
|
275
|
+
const id = this._registerSingleFormula(unitId, subUnitId, formula1, ruleId);
|
|
276
|
+
item[0] = { id, text: formula1 };
|
|
272
277
|
}
|
|
273
|
-
if (
|
|
274
|
-
const
|
|
275
|
-
|
|
278
|
+
if (isFormula2Legal) {
|
|
279
|
+
const id = this._registerSingleFormula(unitId, subUnitId, formula2, ruleId);
|
|
280
|
+
item[1] = { id, text: formula2 };
|
|
276
281
|
}
|
|
277
|
-
|
|
282
|
+
formulaRuleMap.set(ruleId, item);
|
|
278
283
|
}
|
|
279
284
|
}
|
|
280
|
-
removeRule(
|
|
281
|
-
const
|
|
282
|
-
if (!
|
|
285
|
+
removeRule(unitId, subUnitId, ruleId) {
|
|
286
|
+
const item = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
287
|
+
if (!item)
|
|
283
288
|
return;
|
|
284
|
-
const [
|
|
285
|
-
|
|
289
|
+
const [formula1, formula2] = item, idList = [formula1 == null ? void 0 : formula1.id, formula2 == null ? void 0 : formula2.id].filter(Boolean);
|
|
290
|
+
idList.length && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, idList);
|
|
286
291
|
}
|
|
287
|
-
getRuleFormulaResult(
|
|
288
|
-
const
|
|
289
|
-
if (!
|
|
292
|
+
getRuleFormulaResult(unitId, subUnitId, ruleId) {
|
|
293
|
+
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
294
|
+
if (!formulaInfo)
|
|
290
295
|
return Promise.resolve(null);
|
|
291
|
-
const
|
|
296
|
+
const getResult = /* @__PURE__ */ __name(async (info) => info && this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, info.id), "getResult");
|
|
292
297
|
return Promise.all([
|
|
293
|
-
|
|
294
|
-
|
|
298
|
+
getResult(formulaInfo[0]),
|
|
299
|
+
getResult(formulaInfo[1])
|
|
295
300
|
]);
|
|
296
301
|
}
|
|
297
|
-
getRuleFormulaResultSync(
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
300
|
-
return
|
|
301
|
-
if (
|
|
302
|
-
return this._registerOtherFormulaService.getFormulaValueSync(
|
|
302
|
+
getRuleFormulaResultSync(unitId, subUnitId, ruleId) {
|
|
303
|
+
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
304
|
+
if (formulaInfo)
|
|
305
|
+
return formulaInfo.map((i) => {
|
|
306
|
+
if (i)
|
|
307
|
+
return this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, i.id);
|
|
303
308
|
});
|
|
304
309
|
}
|
|
305
|
-
getRuleFormulaInfo(
|
|
306
|
-
return this._ensureRuleFormulaMap(
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
],
|
|
316
|
-
function
|
|
317
|
-
return
|
|
310
|
+
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
311
|
+
return this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
312
|
+
}
|
|
313
|
+
}, __name(_a3, "DataValidationFormulaService"), _a3);
|
|
314
|
+
DataValidationFormulaService = __decorateClass$8([
|
|
315
|
+
__decorateParam$8(0, IUniverInstanceService),
|
|
316
|
+
__decorateParam$8(1, Inject(RegisterOtherFormulaService)),
|
|
317
|
+
__decorateParam$8(2, Inject(DataValidationCacheService)),
|
|
318
|
+
__decorateParam$8(3, Inject(DataValidationModel)),
|
|
319
|
+
__decorateParam$8(4, Inject(DataValidatorRegistryService))
|
|
320
|
+
], DataValidationFormulaService);
|
|
321
|
+
function getCellValueOrigin(cell) {
|
|
322
|
+
return getOriginCellValue(cell);
|
|
318
323
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
__name(getCellValueOrigin, "getCellValueOrigin");
|
|
325
|
+
function getStringCellValue(cell) {
|
|
326
|
+
var _a12;
|
|
327
|
+
return String((_a12 = getCellValueOrigin(cell)) != null ? _a12 : "");
|
|
322
328
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
+
__name(getStringCellValue, "getStringCellValue");
|
|
330
|
+
const _RuleMatrix = class _RuleMatrix {
|
|
331
|
+
constructor(value, _unitId, _subUnitId, _univerInstanceService, _disableTree = !1) {
|
|
332
|
+
__publicField(this, "_map");
|
|
333
|
+
__publicField(this, "_tree", new RBush());
|
|
334
|
+
__publicField(this, "_dirty", !0);
|
|
335
|
+
__publicField(this, "_buildTree", /* @__PURE__ */ __name(() => {
|
|
329
336
|
if (!this._dirty || this._disableTree)
|
|
330
337
|
return;
|
|
331
338
|
this._tree.clear();
|
|
332
|
-
const
|
|
333
|
-
this._map.forEach((
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
minX:
|
|
337
|
-
maxX:
|
|
338
|
-
minY:
|
|
339
|
-
maxY:
|
|
340
|
-
ruleId
|
|
339
|
+
const items = [];
|
|
340
|
+
this._map.forEach((ranges, ruleId) => {
|
|
341
|
+
ranges.forEach((range) => {
|
|
342
|
+
items.push({
|
|
343
|
+
minX: range.startRow,
|
|
344
|
+
maxX: range.endRow,
|
|
345
|
+
minY: range.startColumn,
|
|
346
|
+
maxY: range.endColumn,
|
|
347
|
+
ruleId
|
|
341
348
|
});
|
|
342
349
|
});
|
|
343
|
-
}), this._tree.load(
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
this._unitId =
|
|
350
|
+
}), this._tree.load(items), this._dirty = !1;
|
|
351
|
+
}, "_buildTree"));
|
|
352
|
+
__publicField(this, "_debonceBuildTree", debounce(this._buildTree, 0));
|
|
353
|
+
this._unitId = _unitId, this._subUnitId = _subUnitId, this._univerInstanceService = _univerInstanceService, this._disableTree = _disableTree, this._map = value, this._buildTree();
|
|
347
354
|
}
|
|
348
355
|
get _worksheet() {
|
|
349
|
-
var
|
|
350
|
-
return (
|
|
356
|
+
var _a12;
|
|
357
|
+
return (_a12 = this._univerInstanceService.getUnit(this._unitId, UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a12.getSheetBySheetId(this._subUnitId);
|
|
351
358
|
}
|
|
352
|
-
_addRule(
|
|
359
|
+
_addRule(ruleId, _ranges) {
|
|
353
360
|
if (!this._worksheet)
|
|
354
361
|
return;
|
|
355
|
-
const
|
|
356
|
-
this._map.forEach((
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
}), this._dirty = !0, this._map.set(
|
|
362
|
+
const ranges = Rectangle.mergeRanges(_ranges.map((range) => Range.transformRange(range, this._worksheet)));
|
|
363
|
+
this._map.forEach((value, key) => {
|
|
364
|
+
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
365
|
+
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
366
|
+
}), this._dirty = !0, this._map.set(ruleId, ranges), this._debonceBuildTree();
|
|
360
367
|
}
|
|
361
|
-
addRule(
|
|
362
|
-
this._addRule(
|
|
368
|
+
addRule(rule) {
|
|
369
|
+
this._addRule(rule.uid, rule.ranges);
|
|
363
370
|
}
|
|
364
|
-
removeRange(
|
|
371
|
+
removeRange(_ranges) {
|
|
365
372
|
if (!this._worksheet)
|
|
366
373
|
return;
|
|
367
|
-
const
|
|
368
|
-
this._map.forEach((
|
|
369
|
-
const
|
|
370
|
-
|
|
374
|
+
const ranges = _ranges.map((range) => Range.transformRange(range, this._worksheet));
|
|
375
|
+
this._map.forEach((value, key) => {
|
|
376
|
+
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
377
|
+
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
371
378
|
}), this._dirty = !0, this._debonceBuildTree();
|
|
372
379
|
}
|
|
373
|
-
_removeRule(
|
|
374
|
-
this._map.delete(
|
|
380
|
+
_removeRule(ruleId) {
|
|
381
|
+
this._map.delete(ruleId), this._dirty = !0, this._debonceBuildTree();
|
|
375
382
|
}
|
|
376
|
-
removeRule(
|
|
377
|
-
this._removeRule(
|
|
383
|
+
removeRule(rule) {
|
|
384
|
+
this._removeRule(rule.uid);
|
|
378
385
|
}
|
|
379
|
-
updateRange(
|
|
380
|
-
this._removeRule(
|
|
386
|
+
updateRange(ruleId, _newRanges) {
|
|
387
|
+
this._removeRule(ruleId), this._addRule(ruleId, _newRanges);
|
|
381
388
|
}
|
|
382
|
-
addRangeRules(
|
|
383
|
-
|
|
384
|
-
if (!
|
|
389
|
+
addRangeRules(rules) {
|
|
390
|
+
rules.forEach(({ id: ruleId, ranges }) => {
|
|
391
|
+
if (!ranges.length)
|
|
385
392
|
return;
|
|
386
|
-
let
|
|
387
|
-
|
|
388
|
-
if (
|
|
393
|
+
let current = this._map.get(ruleId);
|
|
394
|
+
current ? (this._map.set(ruleId, Rectangle.mergeRanges([...current, ...ranges])), current = this._map.get(ruleId)) : (current = ranges, this._map.set(ruleId, current)), this._map.forEach((value, key) => {
|
|
395
|
+
if (key === ruleId)
|
|
389
396
|
return;
|
|
390
|
-
const
|
|
391
|
-
|
|
397
|
+
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
398
|
+
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
392
399
|
});
|
|
393
400
|
}), this._dirty = !0, this._debonceBuildTree();
|
|
394
401
|
}
|
|
395
|
-
diff(
|
|
396
|
-
const
|
|
397
|
-
let
|
|
398
|
-
return
|
|
399
|
-
var
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
+
diff(rules) {
|
|
403
|
+
const mutations = [];
|
|
404
|
+
let deleteIndex = 0;
|
|
405
|
+
return rules.forEach((rule, index) => {
|
|
406
|
+
var _a12;
|
|
407
|
+
const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [], oldRanges = rule.ranges;
|
|
408
|
+
newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) && mutations.push({
|
|
402
409
|
type: "update",
|
|
403
|
-
ruleId:
|
|
404
|
-
oldRanges
|
|
405
|
-
newRanges:
|
|
406
|
-
rule
|
|
407
|
-
}),
|
|
410
|
+
ruleId: rule.uid,
|
|
411
|
+
oldRanges,
|
|
412
|
+
newRanges: Rectangle.sort(newRanges),
|
|
413
|
+
rule
|
|
414
|
+
}), newRanges.length === 0 && (mutations.push({
|
|
408
415
|
type: "delete",
|
|
409
|
-
rule
|
|
410
|
-
index:
|
|
411
|
-
}),
|
|
412
|
-
}),
|
|
413
|
-
}
|
|
414
|
-
diffWithAddition(
|
|
415
|
-
const
|
|
416
|
-
let
|
|
417
|
-
return
|
|
418
|
-
var
|
|
419
|
-
const
|
|
420
|
-
|
|
416
|
+
rule,
|
|
417
|
+
index: index - deleteIndex
|
|
418
|
+
}), deleteIndex++);
|
|
419
|
+
}), mutations;
|
|
420
|
+
}
|
|
421
|
+
diffWithAddition(rules, additionRules) {
|
|
422
|
+
const mutations = [];
|
|
423
|
+
let deleteIndex = 0;
|
|
424
|
+
return rules.forEach((rule, index) => {
|
|
425
|
+
var _a12;
|
|
426
|
+
const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [], oldRanges = rule.ranges;
|
|
427
|
+
newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) && mutations.push({
|
|
421
428
|
type: "update",
|
|
422
|
-
ruleId:
|
|
423
|
-
oldRanges
|
|
424
|
-
newRanges:
|
|
425
|
-
rule
|
|
426
|
-
}),
|
|
429
|
+
ruleId: rule.uid,
|
|
430
|
+
oldRanges,
|
|
431
|
+
newRanges: Rectangle.sort(newRanges),
|
|
432
|
+
rule
|
|
433
|
+
}), newRanges.length === 0 && (mutations.push({
|
|
427
434
|
type: "delete",
|
|
428
|
-
rule
|
|
429
|
-
index:
|
|
430
|
-
}),
|
|
431
|
-
}), Array.from(
|
|
432
|
-
var
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
+
rule,
|
|
436
|
+
index: index - deleteIndex
|
|
437
|
+
}), deleteIndex++);
|
|
438
|
+
}), Array.from(additionRules).forEach((rule) => {
|
|
439
|
+
var _a12;
|
|
440
|
+
const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [];
|
|
441
|
+
mutations.push({
|
|
435
442
|
type: "add",
|
|
436
443
|
rule: {
|
|
437
|
-
...
|
|
438
|
-
ranges:
|
|
444
|
+
...rule,
|
|
445
|
+
ranges: Rectangle.sort(newRanges)
|
|
439
446
|
}
|
|
440
447
|
});
|
|
441
|
-
}),
|
|
448
|
+
}), mutations;
|
|
442
449
|
}
|
|
443
450
|
clone() {
|
|
444
|
-
return new
|
|
445
|
-
new Map(
|
|
451
|
+
return new _RuleMatrix(
|
|
452
|
+
new Map(Tools.deepClone(Array.from(this._map.entries()))),
|
|
446
453
|
this._unitId,
|
|
447
454
|
this._subUnitId,
|
|
448
455
|
this._univerInstanceService,
|
|
@@ -450,591 +457,606 @@ class Xe {
|
|
|
450
457
|
!0
|
|
451
458
|
);
|
|
452
459
|
}
|
|
453
|
-
getValue(
|
|
460
|
+
getValue(row, col) {
|
|
454
461
|
this._dirty && this._buildTree();
|
|
455
|
-
const
|
|
456
|
-
minX:
|
|
457
|
-
maxX:
|
|
458
|
-
minY:
|
|
459
|
-
maxY:
|
|
462
|
+
const result = this._tree.search({
|
|
463
|
+
minX: row,
|
|
464
|
+
maxX: row,
|
|
465
|
+
minY: col,
|
|
466
|
+
maxY: col
|
|
460
467
|
});
|
|
461
|
-
return
|
|
468
|
+
return result.length > 0 ? result[0].ruleId : void 0;
|
|
462
469
|
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
470
|
+
};
|
|
471
|
+
__name(_RuleMatrix, "RuleMatrix");
|
|
472
|
+
let RuleMatrix = _RuleMatrix;
|
|
473
|
+
var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
474
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
475
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
476
|
+
return kind && result && __defProp$7(target, key, result), result;
|
|
477
|
+
}, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a4;
|
|
478
|
+
let SheetDataValidationModel = (_a4 = class extends Disposable {
|
|
479
|
+
constructor(_dataValidationModel, _univerInstanceService, _dataValidatorRegistryService, _dataValidationCacheService, _dataValidationFormulaService, _dataValidationCustomFormulaService, _commandService) {
|
|
471
480
|
super();
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
this._dataValidationModel =
|
|
481
|
+
__publicField(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
|
|
482
|
+
__publicField(this, "_validStatusChange$", new Subject());
|
|
483
|
+
__publicField(this, "_ruleChange$", new Subject());
|
|
484
|
+
__publicField(this, "ruleChange$", this._ruleChange$.asObservable());
|
|
485
|
+
__publicField(this, "validStatusChange$", this._validStatusChange$.asObservable());
|
|
486
|
+
this._dataValidationModel = _dataValidationModel, this._univerInstanceService = _univerInstanceService, this._dataValidatorRegistryService = _dataValidatorRegistryService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationFormulaService = _dataValidationFormulaService, this._dataValidationCustomFormulaService = _dataValidationCustomFormulaService, this._commandService = _commandService, this._initRuleUpdateListener(), this.disposeWithMe(() => {
|
|
478
487
|
this._ruleChange$.complete(), this._validStatusChange$.complete();
|
|
479
488
|
}), this._initUniverInstanceListener();
|
|
480
489
|
}
|
|
481
490
|
_initUniverInstanceListener() {
|
|
482
491
|
this.disposeWithMe(
|
|
483
|
-
this._univerInstanceService.unitDisposed$.subscribe((
|
|
484
|
-
this._ruleMatrixMap.delete(
|
|
492
|
+
this._univerInstanceService.unitDisposed$.subscribe((unit) => {
|
|
493
|
+
this._ruleMatrixMap.delete(unit.getUnitId());
|
|
485
494
|
})
|
|
486
495
|
), this.disposeWithMe(
|
|
487
|
-
this._commandService.onCommandExecuted((
|
|
488
|
-
if (
|
|
489
|
-
const { unitId
|
|
490
|
-
|
|
496
|
+
this._commandService.onCommandExecuted((command) => {
|
|
497
|
+
if (command.id === RemoveSheetMutation.id) {
|
|
498
|
+
const { unitId, subUnitId } = command.params, subUnitMap = this._ruleMatrixMap.get(unitId);
|
|
499
|
+
subUnitMap && subUnitMap.delete(subUnitId);
|
|
491
500
|
}
|
|
492
501
|
})
|
|
493
502
|
);
|
|
494
503
|
}
|
|
495
504
|
_initRuleUpdateListener() {
|
|
496
|
-
const
|
|
497
|
-
for (const [
|
|
498
|
-
for (const [
|
|
499
|
-
for (const
|
|
500
|
-
this._addRule(
|
|
505
|
+
const allRules = this._dataValidationModel.getAll();
|
|
506
|
+
for (const [unitId, subUnitMap] of allRules)
|
|
507
|
+
for (const [subUnitId, rules] of subUnitMap)
|
|
508
|
+
for (const rule of rules)
|
|
509
|
+
this._addRule(unitId, subUnitId, rule), this._ruleChange$.next({
|
|
501
510
|
type: "add",
|
|
502
|
-
unitId
|
|
503
|
-
subUnitId
|
|
504
|
-
rule
|
|
511
|
+
unitId,
|
|
512
|
+
subUnitId,
|
|
513
|
+
rule,
|
|
505
514
|
source: "patched"
|
|
506
515
|
});
|
|
507
516
|
this.disposeWithMe(
|
|
508
|
-
this._dataValidationModel.ruleChange$.subscribe((
|
|
509
|
-
switch (
|
|
517
|
+
this._dataValidationModel.ruleChange$.subscribe((ruleChange) => {
|
|
518
|
+
switch (ruleChange.type) {
|
|
510
519
|
case "add":
|
|
511
|
-
this._addRule(
|
|
520
|
+
this._addRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
512
521
|
break;
|
|
513
522
|
case "update":
|
|
514
|
-
this._updateRule(
|
|
523
|
+
this._updateRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule.uid, ruleChange.oldRule, ruleChange.updatePayload);
|
|
515
524
|
break;
|
|
516
525
|
case "remove":
|
|
517
|
-
this._removeRule(
|
|
526
|
+
this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
518
527
|
break;
|
|
519
528
|
}
|
|
520
|
-
this._ruleChange$.next(
|
|
529
|
+
this._ruleChange$.next(ruleChange);
|
|
521
530
|
})
|
|
522
531
|
);
|
|
523
532
|
}
|
|
524
|
-
_ensureRuleMatrix(
|
|
525
|
-
let
|
|
526
|
-
|
|
527
|
-
let
|
|
528
|
-
return
|
|
533
|
+
_ensureRuleMatrix(unitId, subUnitId) {
|
|
534
|
+
let unitMap = this._ruleMatrixMap.get(unitId);
|
|
535
|
+
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._ruleMatrixMap.set(unitId, unitMap));
|
|
536
|
+
let matrix = unitMap.get(subUnitId);
|
|
537
|
+
return matrix || (matrix = new RuleMatrix(/* @__PURE__ */ new Map(), unitId, subUnitId, this._univerInstanceService), unitMap.set(subUnitId, matrix)), matrix;
|
|
529
538
|
}
|
|
530
|
-
_addRuleSideEffect(
|
|
531
|
-
this._ensureRuleMatrix(
|
|
539
|
+
_addRuleSideEffect(unitId, subUnitId, rule) {
|
|
540
|
+
this._ensureRuleMatrix(unitId, subUnitId).addRule(rule), this._dataValidationCacheService.addRule(unitId, subUnitId, rule), this._dataValidationFormulaService.addRule(unitId, subUnitId, rule), this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, rule);
|
|
532
541
|
}
|
|
533
|
-
_addRule(
|
|
534
|
-
(Array.isArray(
|
|
535
|
-
this._addRuleSideEffect(
|
|
542
|
+
_addRule(unitId, subUnitId, rule) {
|
|
543
|
+
(Array.isArray(rule) ? rule : [rule]).forEach((item) => {
|
|
544
|
+
this._addRuleSideEffect(unitId, subUnitId, item);
|
|
536
545
|
});
|
|
537
546
|
}
|
|
538
|
-
_updateRule(
|
|
539
|
-
const
|
|
540
|
-
...
|
|
541
|
-
...
|
|
547
|
+
_updateRule(unitId, subUnitId, ruleId, oldRule, payload) {
|
|
548
|
+
const ruleMatrix = this._ensureRuleMatrix(unitId, subUnitId), newRule = {
|
|
549
|
+
...oldRule,
|
|
550
|
+
...payload.payload
|
|
542
551
|
};
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
_removeRule(
|
|
546
|
-
this._ensureRuleMatrix(
|
|
547
|
-
}
|
|
548
|
-
getValidator(
|
|
549
|
-
return this._dataValidatorRegistryService.getValidatorItem(
|
|
550
|
-
}
|
|
551
|
-
getRuleIdByLocation(
|
|
552
|
-
return this._ensureRuleMatrix(
|
|
553
|
-
}
|
|
554
|
-
getRuleByLocation(
|
|
555
|
-
const
|
|
556
|
-
if (
|
|
557
|
-
return this._dataValidationModel.getRuleById(
|
|
558
|
-
}
|
|
559
|
-
validator(
|
|
560
|
-
const { col
|
|
561
|
-
|
|
562
|
-
unitId
|
|
563
|
-
subUnitId
|
|
564
|
-
ruleId:
|
|
565
|
-
status
|
|
566
|
-
row
|
|
567
|
-
col
|
|
552
|
+
payload.type === UpdateRuleType.RANGE ? ruleMatrix.updateRange(ruleId, payload.payload) : payload.type === UpdateRuleType.ALL && ruleMatrix.updateRange(ruleId, payload.payload.ranges), this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule), this._dataValidationCacheService.addRule(unitId, subUnitId, newRule), this._dataValidationFormulaService.removeRule(unitId, subUnitId, oldRule.uid), this._dataValidationFormulaService.addRule(unitId, subUnitId, newRule), this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, ruleId), this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, newRule);
|
|
553
|
+
}
|
|
554
|
+
_removeRule(unitId, subUnitId, oldRule) {
|
|
555
|
+
this._ensureRuleMatrix(unitId, subUnitId).removeRule(oldRule), this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule), this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, oldRule.uid);
|
|
556
|
+
}
|
|
557
|
+
getValidator(type) {
|
|
558
|
+
return this._dataValidatorRegistryService.getValidatorItem(type);
|
|
559
|
+
}
|
|
560
|
+
getRuleIdByLocation(unitId, subUnitId, row, col) {
|
|
561
|
+
return this._ensureRuleMatrix(unitId, subUnitId).getValue(row, col);
|
|
562
|
+
}
|
|
563
|
+
getRuleByLocation(unitId, subUnitId, row, col) {
|
|
564
|
+
const ruleId = this.getRuleIdByLocation(unitId, subUnitId, row, col);
|
|
565
|
+
if (ruleId)
|
|
566
|
+
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
567
|
+
}
|
|
568
|
+
validator(rule, pos, _onCompete) {
|
|
569
|
+
const { col, row, unitId, subUnitId, worksheet } = pos, onCompete = /* @__PURE__ */ __name((status, changed) => {
|
|
570
|
+
_onCompete && _onCompete(status, changed), changed && this._validStatusChange$.next({
|
|
571
|
+
unitId,
|
|
572
|
+
subUnitId,
|
|
573
|
+
ruleId: rule.uid,
|
|
574
|
+
status,
|
|
575
|
+
row,
|
|
576
|
+
col
|
|
568
577
|
});
|
|
569
|
-
},
|
|
570
|
-
if (
|
|
571
|
-
const
|
|
572
|
-
return
|
|
578
|
+
}, "onCompete"), cell = worksheet.getCellValueOnly(row, col), validator = this.getValidator(rule.type), cellRaw = worksheet.getCellRaw(row, col), cellValue = getCellValueOrigin(cellRaw);
|
|
579
|
+
if (validator) {
|
|
580
|
+
const cache = this._dataValidationCacheService.ensureCache(unitId, subUnitId), current = cache.getValue(row, col);
|
|
581
|
+
return current == null ? (cache.setValue(row, col, DataValidationStatus.VALIDATING), validator.validator(
|
|
573
582
|
{
|
|
574
|
-
value:
|
|
575
|
-
unitId
|
|
576
|
-
subUnitId
|
|
577
|
-
row
|
|
578
|
-
column:
|
|
579
|
-
worksheet:
|
|
580
|
-
workbook:
|
|
581
|
-
interceptValue:
|
|
582
|
-
t:
|
|
583
|
+
value: cellValue,
|
|
584
|
+
unitId,
|
|
585
|
+
subUnitId,
|
|
586
|
+
row,
|
|
587
|
+
column: col,
|
|
588
|
+
worksheet: pos.worksheet,
|
|
589
|
+
workbook: pos.workbook,
|
|
590
|
+
interceptValue: getCellValueOrigin(cell),
|
|
591
|
+
t: cellRaw == null ? void 0 : cellRaw.t
|
|
583
592
|
},
|
|
584
|
-
|
|
585
|
-
).then((
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
}),
|
|
593
|
+
rule
|
|
594
|
+
).then((status) => {
|
|
595
|
+
const realStatus = status ? DataValidationStatus.VALID : DataValidationStatus.INVALID;
|
|
596
|
+
realStatus === DataValidationStatus.VALID ? cache.realDeleteValue(row, col) : cache.setValue(row, col, realStatus);
|
|
597
|
+
const now = cache.getValue(row, col);
|
|
598
|
+
onCompete(realStatus, current !== now);
|
|
599
|
+
}), DataValidationStatus.VALIDATING) : (onCompete(current != null ? current : DataValidationStatus.VALID, !1), current != null ? current : DataValidationStatus.VALID);
|
|
591
600
|
} else
|
|
592
|
-
return
|
|
601
|
+
return onCompete(DataValidationStatus.VALID, !1), DataValidationStatus.VALID;
|
|
593
602
|
}
|
|
594
|
-
getRuleObjectMatrix(
|
|
595
|
-
return this._ensureRuleMatrix(
|
|
603
|
+
getRuleObjectMatrix(unitId, subUnitId) {
|
|
604
|
+
return this._ensureRuleMatrix(unitId, subUnitId);
|
|
596
605
|
}
|
|
597
|
-
getRuleById(
|
|
598
|
-
return this._dataValidationModel.getRuleById(
|
|
606
|
+
getRuleById(unitId, subUnitId, ruleId) {
|
|
607
|
+
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
599
608
|
}
|
|
600
|
-
getRuleIndex(
|
|
601
|
-
return this._dataValidationModel.getRuleIndex(
|
|
609
|
+
getRuleIndex(unitId, subUnitId, ruleId) {
|
|
610
|
+
return this._dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId);
|
|
602
611
|
}
|
|
603
|
-
getRules(
|
|
604
|
-
return [...this._dataValidationModel.getRules(
|
|
612
|
+
getRules(unitId, subUnitId) {
|
|
613
|
+
return [...this._dataValidationModel.getRules(unitId, subUnitId)];
|
|
605
614
|
}
|
|
606
|
-
getUnitRules(
|
|
607
|
-
return this._dataValidationModel.getUnitRules(
|
|
615
|
+
getUnitRules(unitId) {
|
|
616
|
+
return this._dataValidationModel.getUnitRules(unitId);
|
|
608
617
|
}
|
|
609
|
-
deleteUnitRules(
|
|
610
|
-
return this._dataValidationModel.deleteUnitRules(
|
|
618
|
+
deleteUnitRules(unitId) {
|
|
619
|
+
return this._dataValidationModel.deleteUnitRules(unitId);
|
|
611
620
|
}
|
|
612
|
-
getSubUnitIds(
|
|
613
|
-
return this._dataValidationModel.getSubUnitIds(
|
|
621
|
+
getSubUnitIds(unitId) {
|
|
622
|
+
return this._dataValidationModel.getSubUnitIds(unitId);
|
|
614
623
|
}
|
|
615
624
|
getAll() {
|
|
616
625
|
return this._dataValidationModel.getAll();
|
|
617
626
|
}
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
],
|
|
628
|
-
const
|
|
629
|
-
function
|
|
630
|
-
return
|
|
627
|
+
}, __name(_a4, "SheetDataValidationModel"), _a4);
|
|
628
|
+
SheetDataValidationModel = __decorateClass$7([
|
|
629
|
+
__decorateParam$7(0, Inject(DataValidationModel)),
|
|
630
|
+
__decorateParam$7(1, IUniverInstanceService),
|
|
631
|
+
__decorateParam$7(2, Inject(DataValidatorRegistryService)),
|
|
632
|
+
__decorateParam$7(3, Inject(DataValidationCacheService)),
|
|
633
|
+
__decorateParam$7(4, Inject(DataValidationFormulaService)),
|
|
634
|
+
__decorateParam$7(5, Inject(DataValidationCustomFormulaService)),
|
|
635
|
+
__decorateParam$7(6, ICommandService)
|
|
636
|
+
], SheetDataValidationModel);
|
|
637
|
+
const CHECKBOX_FORMULA_1 = 1, CHECKBOX_FORMULA_2 = 0;
|
|
638
|
+
function getFailMessage(formula, localeService) {
|
|
639
|
+
return Tools.isBlank(formula) ? localeService.t("dataValidation.validFail.value") : isFormulaString(formula) ? localeService.t("dataValidation.validFail.primitive") : "";
|
|
631
640
|
}
|
|
632
|
-
|
|
633
|
-
class
|
|
641
|
+
__name(getFailMessage, "getFailMessage");
|
|
642
|
+
const transformCheckboxValue = /* @__PURE__ */ __name((value) => Tools.isDefine(value) && String(value).toLowerCase() === "true" ? "1" : String(value).toLowerCase() === "false" ? "0" : value, "transformCheckboxValue"), _CheckboxValidator = class _CheckboxValidator extends BaseDataValidator {
|
|
634
643
|
constructor() {
|
|
635
644
|
super(...arguments);
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
const { unitId
|
|
644
|
-
return !
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
validatorFormula(
|
|
648
|
-
const { formula1
|
|
649
|
-
if (
|
|
645
|
+
__publicField(this, "id", DataValidationType.CHECKBOX);
|
|
646
|
+
__publicField(this, "title", "dataValidation.checkbox.title");
|
|
647
|
+
__publicField(this, "operators", []);
|
|
648
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
649
|
+
__publicField(this, "offsetFormulaByRange", !1);
|
|
650
|
+
__publicField(this, "_formulaService", this.injector.get(DataValidationFormulaService));
|
|
651
|
+
__publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name((rule, cellValue, pos) => {
|
|
652
|
+
const { unitId, subUnitId } = pos, { formula1, formula2 } = this.parseFormulaSync(rule, unitId, subUnitId), valueStr = `${cellValue != null ? cellValue : ""}`;
|
|
653
|
+
return !valueStr || valueStr === `${formula1}` || valueStr === `${formula2}`;
|
|
654
|
+
}, "skipDefaultFontRender"));
|
|
655
|
+
}
|
|
656
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
657
|
+
const { formula1, formula2 } = rule, isEqual = formula1 === formula2;
|
|
658
|
+
if (Tools.isBlank(formula1) && Tools.isBlank(formula2))
|
|
650
659
|
return {
|
|
651
660
|
success: !0
|
|
652
661
|
};
|
|
653
|
-
if (
|
|
662
|
+
if (isEqual)
|
|
654
663
|
return {
|
|
655
664
|
success: !1,
|
|
656
665
|
formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
|
|
657
666
|
formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
|
|
658
667
|
};
|
|
659
|
-
const
|
|
668
|
+
const error1 = getFailMessage(formula1, this.localeService), error2 = getFailMessage(formula2, this.localeService);
|
|
660
669
|
return {
|
|
661
|
-
success: !
|
|
662
|
-
formula1:
|
|
663
|
-
formula2:
|
|
670
|
+
success: !error1 && !error2,
|
|
671
|
+
formula1: error1,
|
|
672
|
+
formula2: error2
|
|
664
673
|
};
|
|
665
674
|
}
|
|
666
|
-
async parseFormula(
|
|
667
|
-
var
|
|
668
|
-
const { formula1
|
|
675
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
676
|
+
var _a12, _b, _c, _d;
|
|
677
|
+
const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_d = (_c = results == null ? void 0 : results[1]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : formula2, isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
|
|
669
678
|
return {
|
|
670
|
-
formula1:
|
|
671
|
-
formula2:
|
|
672
|
-
originFormula1
|
|
673
|
-
originFormula2
|
|
674
|
-
isFormulaValid
|
|
679
|
+
formula1: transformCheckboxValue(originFormula1),
|
|
680
|
+
formula2: transformCheckboxValue(originFormula2),
|
|
681
|
+
originFormula1,
|
|
682
|
+
originFormula2,
|
|
683
|
+
isFormulaValid
|
|
675
684
|
};
|
|
676
685
|
}
|
|
677
|
-
getExtraStyle(
|
|
686
|
+
getExtraStyle(rule, value) {
|
|
678
687
|
return {
|
|
679
|
-
tb:
|
|
688
|
+
tb: WrapStrategy.CLIP
|
|
680
689
|
};
|
|
681
690
|
}
|
|
682
|
-
parseFormulaSync(
|
|
683
|
-
var
|
|
684
|
-
const { formula1
|
|
691
|
+
parseFormulaSync(rule, unitId, subUnitId) {
|
|
692
|
+
var _a12, _b, _c, _d;
|
|
693
|
+
const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_d = (_c = results == null ? void 0 : results[1]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : formula2, isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
|
|
685
694
|
return {
|
|
686
|
-
formula1:
|
|
687
|
-
formula2:
|
|
688
|
-
originFormula1
|
|
689
|
-
originFormula2
|
|
690
|
-
isFormulaValid
|
|
695
|
+
formula1: transformCheckboxValue(originFormula1),
|
|
696
|
+
formula2: transformCheckboxValue(originFormula2),
|
|
697
|
+
originFormula1,
|
|
698
|
+
originFormula2,
|
|
699
|
+
isFormulaValid
|
|
691
700
|
};
|
|
692
701
|
}
|
|
693
|
-
async isValidType(
|
|
694
|
-
const { value
|
|
695
|
-
return !
|
|
702
|
+
async isValidType(cellInfo, formula, rule) {
|
|
703
|
+
const { value, unitId, subUnitId } = cellInfo, { formula1, formula2, originFormula1, originFormula2 } = await this.parseFormula(rule, unitId, subUnitId);
|
|
704
|
+
return !Tools.isDefine(formula1) || !Tools.isDefine(formula2) ? !0 : Tools.isDefine(value) && (String(value) === String(formula1) || String(value) === String(formula2) || String(value) === String(originFormula1 != null ? originFormula1 : "") || String(value) === String(originFormula2 != null ? originFormula2 : ""));
|
|
696
705
|
}
|
|
697
|
-
generateRuleErrorMessage(
|
|
706
|
+
generateRuleErrorMessage(rule) {
|
|
698
707
|
return this.localeService.t("dataValidation.checkbox.error");
|
|
699
708
|
}
|
|
700
|
-
}
|
|
701
|
-
const na = {
|
|
702
|
-
[h.BETWEEN]: "dataValidation.date.operators.between",
|
|
703
|
-
[h.EQUAL]: "dataValidation.date.operators.equal",
|
|
704
|
-
[h.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
|
|
705
|
-
[h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
|
|
706
|
-
[h.LESS_THAN]: "dataValidation.date.operators.lessThan",
|
|
707
|
-
[h.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
|
|
708
|
-
[h.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
|
|
709
|
-
[h.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
|
|
710
709
|
};
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
[
|
|
715
|
-
[
|
|
716
|
-
[
|
|
717
|
-
[
|
|
718
|
-
[
|
|
719
|
-
[
|
|
720
|
-
[
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
[
|
|
726
|
-
[
|
|
727
|
-
[
|
|
728
|
-
[
|
|
729
|
-
[
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
710
|
+
__name(_CheckboxValidator, "CheckboxValidator");
|
|
711
|
+
let CheckboxValidator = _CheckboxValidator;
|
|
712
|
+
const DateOperatorNameMap = {
|
|
713
|
+
[DataValidationOperator.BETWEEN]: "dataValidation.date.operators.between",
|
|
714
|
+
[DataValidationOperator.EQUAL]: "dataValidation.date.operators.equal",
|
|
715
|
+
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
|
|
716
|
+
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
|
|
717
|
+
[DataValidationOperator.LESS_THAN]: "dataValidation.date.operators.lessThan",
|
|
718
|
+
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
|
|
719
|
+
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
|
|
720
|
+
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
|
|
721
|
+
};
|
|
722
|
+
DataValidationOperator.BETWEEN + "", DataValidationOperator.EQUAL + "", DataValidationOperator.GREATER_THAN + "", DataValidationOperator.GREATER_THAN_OR_EQUAL + "", DataValidationOperator.LESS_THAN + "", DataValidationOperator.LESS_THAN_OR_EQUAL + "", DataValidationOperator.NOT_BETWEEN + "", DataValidationOperator.NOT_EQUAL + "";
|
|
723
|
+
const DateOperatorTitleMap = {
|
|
724
|
+
[DataValidationOperator.BETWEEN]: "dataValidation.date.ruleName.between",
|
|
725
|
+
[DataValidationOperator.EQUAL]: "dataValidation.date.ruleName.equal",
|
|
726
|
+
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
|
|
727
|
+
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
|
|
728
|
+
[DataValidationOperator.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
|
|
729
|
+
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
|
|
730
|
+
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
|
|
731
|
+
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
|
|
732
|
+
}, DateOperatorErrorTitleMap = {
|
|
733
|
+
[DataValidationOperator.BETWEEN]: "dataValidation.date.errorMsg.between",
|
|
734
|
+
[DataValidationOperator.EQUAL]: "dataValidation.date.errorMsg.equal",
|
|
735
|
+
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
|
|
736
|
+
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
|
|
737
|
+
[DataValidationOperator.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
|
|
738
|
+
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
|
|
739
|
+
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
|
|
740
|
+
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
|
|
741
|
+
}, TWO_FORMULA_OPERATOR_COUNT = [
|
|
742
|
+
DataValidationOperator.BETWEEN,
|
|
743
|
+
DataValidationOperator.NOT_BETWEEN
|
|
744
|
+
], FORMULA1 = "{FORMULA1}", FORMULA2 = "{FORMULA2}";
|
|
745
|
+
function serializeListOptions(options) {
|
|
746
|
+
return options.filter(Boolean).join(",");
|
|
736
747
|
}
|
|
737
|
-
|
|
738
|
-
|
|
748
|
+
__name(serializeListOptions, "serializeListOptions");
|
|
749
|
+
function deserializeListOptions(optionsStr) {
|
|
750
|
+
return optionsStr.split(",").filter(Boolean);
|
|
739
751
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
752
|
+
__name(deserializeListOptions, "deserializeListOptions");
|
|
753
|
+
function getDataValidationCellValue(cellData) {
|
|
754
|
+
const cellValue = getCellValueOrigin(cellData);
|
|
755
|
+
return cellValue == null ? "" : cellValue.toString();
|
|
743
756
|
}
|
|
744
|
-
|
|
745
|
-
|
|
757
|
+
__name(getDataValidationCellValue, "getDataValidationCellValue");
|
|
758
|
+
function getTransformedFormula(lexerTreeBuilder, rule, position) {
|
|
759
|
+
const { formula1, formula2 } = rule, originStartRow = rule.ranges[0].startRow, originStartColumn = rule.ranges[0].startColumn, offsetRow = position.row - originStartRow, offsetColumn = position.col - originStartColumn, transformedFormula1 = isFormulaString(formula1) ? lexerTreeBuilder.moveFormulaRefOffset(formula1, offsetColumn, offsetRow, !0) : formula1, transformedFormula2 = isFormulaString(formula2) ? lexerTreeBuilder.moveFormulaRefOffset(formula2, offsetColumn, offsetRow, !0) : formula2;
|
|
746
760
|
return {
|
|
747
|
-
transformedFormula1
|
|
748
|
-
transformedFormula2
|
|
761
|
+
transformedFormula1,
|
|
762
|
+
transformedFormula2
|
|
749
763
|
};
|
|
750
764
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
765
|
+
__name(getTransformedFormula, "getTransformedFormula");
|
|
766
|
+
const transformDate2SerialNumber = /* @__PURE__ */ __name((value) => {
|
|
767
|
+
var _a12, _b;
|
|
768
|
+
if (value == null || typeof value == "boolean")
|
|
754
769
|
return;
|
|
755
|
-
if (typeof
|
|
756
|
-
return +
|
|
757
|
-
const
|
|
758
|
-
return
|
|
759
|
-
}
|
|
760
|
-
class da extends k {
|
|
770
|
+
if (typeof value == "number" || !Number.isNaN(+value))
|
|
771
|
+
return +value;
|
|
772
|
+
const v = (_a12 = numfmt.parseDate(value)) == null ? void 0 : _a12.v;
|
|
773
|
+
return Tools.isDefine(v) ? v : (_b = numfmt.parseDate(dayjs(value).format("YYYY-MM-DD HH:mm:ss"))) == null ? void 0 : _b.v;
|
|
774
|
+
}, "transformDate2SerialNumber"), _DateValidator = class _DateValidator extends BaseDataValidator {
|
|
761
775
|
constructor() {
|
|
762
776
|
super(...arguments);
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
777
|
+
__publicField(this, "id", DataValidationType.DATE);
|
|
778
|
+
__publicField(this, "title", "dataValidation.date.title");
|
|
779
|
+
__publicField(this, "operators", [
|
|
780
|
+
DataValidationOperator.BETWEEN,
|
|
781
|
+
DataValidationOperator.EQUAL,
|
|
782
|
+
DataValidationOperator.GREATER_THAN,
|
|
783
|
+
DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
784
|
+
DataValidationOperator.LESS_THAN,
|
|
785
|
+
DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
786
|
+
DataValidationOperator.NOT_BETWEEN,
|
|
787
|
+
DataValidationOperator.NOT_EQUAL
|
|
774
788
|
]);
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
789
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
790
|
+
__publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
791
|
+
__publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
|
|
778
792
|
}
|
|
779
|
-
async parseFormula(
|
|
780
|
-
const
|
|
793
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
794
|
+
const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, isFormulaValid = isLegalFormulaResult(String(formulaResult1 == null ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 == null ? void 0 : formulaResult2.v));
|
|
781
795
|
return {
|
|
782
|
-
formula1:
|
|
783
|
-
formula2:
|
|
784
|
-
isFormulaValid
|
|
796
|
+
formula1: transformDate2SerialNumber(isFormulaString(formula1) ? formulaResult1 == null ? void 0 : formulaResult1.v : formula1),
|
|
797
|
+
formula2: transformDate2SerialNumber(isFormulaString(formula2) ? formulaResult2 == null ? void 0 : formulaResult2.v : formula2),
|
|
798
|
+
isFormulaValid
|
|
785
799
|
};
|
|
786
800
|
}
|
|
787
|
-
async isValidType(
|
|
788
|
-
const { interceptValue
|
|
789
|
-
return typeof
|
|
801
|
+
async isValidType(info) {
|
|
802
|
+
const { interceptValue, value } = info;
|
|
803
|
+
return typeof value == "number" && typeof interceptValue == "string" ? !0 : typeof interceptValue == "string" ? !!numfmt.parseDate(interceptValue) : !1;
|
|
790
804
|
}
|
|
791
|
-
_validatorSingleFormula(
|
|
792
|
-
return !
|
|
805
|
+
_validatorSingleFormula(formula) {
|
|
806
|
+
return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula) || !!(formula && numfmt.parseDate(formula)));
|
|
793
807
|
}
|
|
794
|
-
validatorFormula(
|
|
795
|
-
const
|
|
796
|
-
if (!
|
|
808
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
809
|
+
const operator = rule.operator;
|
|
810
|
+
if (!operator)
|
|
797
811
|
return {
|
|
798
812
|
success: !1
|
|
799
813
|
};
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
802
|
-
const
|
|
814
|
+
const formula1Success = this._validatorSingleFormula(rule.formula1), errorMsg = this.localeService.t("dataValidation.validFail.date");
|
|
815
|
+
if (TWO_FORMULA_OPERATOR_COUNT.includes(operator)) {
|
|
816
|
+
const formula2Success = this._validatorSingleFormula(rule.formula2);
|
|
803
817
|
return {
|
|
804
|
-
success:
|
|
805
|
-
formula1:
|
|
806
|
-
formula2:
|
|
818
|
+
success: formula1Success && formula2Success,
|
|
819
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
820
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
807
821
|
};
|
|
808
822
|
}
|
|
809
823
|
return {
|
|
810
|
-
success:
|
|
811
|
-
formula1:
|
|
824
|
+
success: formula1Success,
|
|
825
|
+
formula1: formula1Success ? void 0 : errorMsg
|
|
812
826
|
};
|
|
813
827
|
}
|
|
814
|
-
normalizeFormula(
|
|
815
|
-
const { formula1
|
|
816
|
-
var
|
|
817
|
-
if (!
|
|
818
|
-
return
|
|
819
|
-
let
|
|
820
|
-
if (!Number.isNaN(+
|
|
821
|
-
|
|
828
|
+
normalizeFormula(rule, _unitId, _subUnitId) {
|
|
829
|
+
const { formula1, formula2, bizInfo } = rule, normlizeSingleFormula = /* @__PURE__ */ __name((formula) => {
|
|
830
|
+
var _a12;
|
|
831
|
+
if (!formula)
|
|
832
|
+
return formula;
|
|
833
|
+
let date;
|
|
834
|
+
if (!Number.isNaN(+formula))
|
|
835
|
+
date = numfmt.dateFromSerial(+formula);
|
|
822
836
|
else {
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
837
|
+
const res = (_a12 = numfmt.parseDate(formula)) == null ? void 0 : _a12.v;
|
|
838
|
+
if (res == null)
|
|
825
839
|
return "";
|
|
826
|
-
|
|
840
|
+
date = numfmt.dateFromSerial(res);
|
|
827
841
|
}
|
|
828
|
-
return
|
|
829
|
-
};
|
|
842
|
+
return dayjs(`${date[0]}/${date[1]}/${date[2]} ${date[3]}:${date[4]}:${date[5]}`).format(bizInfo != null && bizInfo.showTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD");
|
|
843
|
+
}, "normlizeSingleFormula");
|
|
830
844
|
return {
|
|
831
|
-
formula1:
|
|
832
|
-
formula2:
|
|
845
|
+
formula1: isFormulaString(formula1) ? formula1 : normlizeSingleFormula(`${formula1}`),
|
|
846
|
+
formula2: isFormulaString(formula2) ? formula2 : normlizeSingleFormula(`${formula2}`)
|
|
833
847
|
};
|
|
834
848
|
}
|
|
835
|
-
transform(
|
|
836
|
-
const { value
|
|
849
|
+
transform(cellInfo, _formula, _rule) {
|
|
850
|
+
const { value } = cellInfo;
|
|
837
851
|
return {
|
|
838
|
-
...
|
|
839
|
-
value:
|
|
852
|
+
...cellInfo,
|
|
853
|
+
value: transformDate2SerialNumber(value)
|
|
840
854
|
};
|
|
841
855
|
}
|
|
842
856
|
get operatorNames() {
|
|
843
|
-
return this.operators.map((
|
|
857
|
+
return this.operators.map((operator) => this.localeService.t(DateOperatorNameMap[operator]));
|
|
844
858
|
}
|
|
845
|
-
generateRuleName(
|
|
846
|
-
var
|
|
847
|
-
if (!
|
|
859
|
+
generateRuleName(rule) {
|
|
860
|
+
var _a12, _b;
|
|
861
|
+
if (!rule.operator)
|
|
848
862
|
return this.titleStr;
|
|
849
|
-
const
|
|
850
|
-
return `${this.titleStr} ${
|
|
863
|
+
const ruleName = this.localeService.t(DateOperatorTitleMap[rule.operator]).replace(FORMULA1, (_a12 = rule.formula1) != null ? _a12 : "").replace(FORMULA2, (_b = rule.formula2) != null ? _b : "");
|
|
864
|
+
return `${this.titleStr} ${ruleName}`;
|
|
851
865
|
}
|
|
852
|
-
generateRuleErrorMessage(
|
|
853
|
-
if (!
|
|
866
|
+
generateRuleErrorMessage(rule, pos) {
|
|
867
|
+
if (!rule.operator)
|
|
854
868
|
return this.titleStr;
|
|
855
|
-
const { transformedFormula1
|
|
856
|
-
return `${this.localeService.t(
|
|
869
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
|
|
870
|
+
return `${this.localeService.t(DateOperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
|
|
857
871
|
}
|
|
858
|
-
}
|
|
859
|
-
h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
|
|
860
|
-
h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
|
|
861
|
-
const ht = {
|
|
862
|
-
[h.BETWEEN]: "dataValidation.errorMsg.between",
|
|
863
|
-
[h.EQUAL]: "dataValidation.errorMsg.equal",
|
|
864
|
-
[h.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
|
|
865
|
-
[h.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
|
|
866
|
-
[h.LESS_THAN]: "dataValidation.errorMsg.lessThan",
|
|
867
|
-
[h.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
|
|
868
|
-
[h.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
|
|
869
|
-
[h.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
|
|
870
872
|
};
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
873
|
+
__name(_DateValidator, "DateValidator");
|
|
874
|
+
let DateValidator = _DateValidator;
|
|
875
|
+
DataValidationOperator.BETWEEN + "", DataValidationOperator.EQUAL + "", DataValidationOperator.GREATER_THAN + "", DataValidationOperator.GREATER_THAN_OR_EQUAL + "", DataValidationOperator.LESS_THAN + "", DataValidationOperator.LESS_THAN_OR_EQUAL + "", DataValidationOperator.NOT_BETWEEN + "", DataValidationOperator.NOT_EQUAL + "";
|
|
876
|
+
DataValidationOperator.BETWEEN + "", DataValidationOperator.EQUAL + "", DataValidationOperator.GREATER_THAN + "", DataValidationOperator.GREATER_THAN_OR_EQUAL + "", DataValidationOperator.LESS_THAN + "", DataValidationOperator.LESS_THAN_OR_EQUAL + "", DataValidationOperator.NOT_BETWEEN + "", DataValidationOperator.NOT_EQUAL + "";
|
|
877
|
+
const OperatorErrorTitleMap = {
|
|
878
|
+
[DataValidationOperator.BETWEEN]: "dataValidation.errorMsg.between",
|
|
879
|
+
[DataValidationOperator.EQUAL]: "dataValidation.errorMsg.equal",
|
|
880
|
+
[DataValidationOperator.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
|
|
881
|
+
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
|
|
882
|
+
[DataValidationOperator.LESS_THAN]: "dataValidation.errorMsg.lessThan",
|
|
883
|
+
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
|
|
884
|
+
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
|
|
885
|
+
[DataValidationOperator.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
|
|
886
|
+
};
|
|
887
|
+
function getCellValueNumber(cellValue) {
|
|
888
|
+
let str = cellValue;
|
|
889
|
+
return typeof cellValue == "string" ? ((cellValue.startsWith("¥") || cellValue.startsWith("$")) && (str = cellValue.slice(1)), +str) : +cellValue;
|
|
874
890
|
}
|
|
875
|
-
|
|
891
|
+
__name(getCellValueNumber, "getCellValueNumber");
|
|
892
|
+
const _DecimalValidator = class _DecimalValidator extends BaseDataValidator {
|
|
876
893
|
constructor() {
|
|
877
894
|
super(...arguments);
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
895
|
+
__publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
896
|
+
__publicField(this, "id", DataValidationType.DECIMAL);
|
|
897
|
+
__publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
|
|
898
|
+
__publicField(this, "title", "dataValidation.decimal.title");
|
|
899
|
+
__publicField(this, "operators", [
|
|
900
|
+
DataValidationOperator.BETWEEN,
|
|
901
|
+
DataValidationOperator.EQUAL,
|
|
902
|
+
DataValidationOperator.GREATER_THAN,
|
|
903
|
+
DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
904
|
+
DataValidationOperator.LESS_THAN,
|
|
905
|
+
DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
906
|
+
DataValidationOperator.NOT_BETWEEN,
|
|
907
|
+
DataValidationOperator.NOT_EQUAL
|
|
891
908
|
]);
|
|
892
|
-
|
|
909
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
893
910
|
}
|
|
894
|
-
_isFormulaOrNumber(
|
|
895
|
-
return !
|
|
911
|
+
_isFormulaOrNumber(formula) {
|
|
912
|
+
return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula));
|
|
896
913
|
}
|
|
897
|
-
async isValidType(
|
|
898
|
-
const { value:
|
|
899
|
-
return !Number.isNaN(
|
|
914
|
+
async isValidType(cellInfo, formula, rule) {
|
|
915
|
+
const { value: cellValue } = cellInfo;
|
|
916
|
+
return !Number.isNaN(getCellValueNumber(cellValue));
|
|
900
917
|
}
|
|
901
|
-
transform(
|
|
902
|
-
const { value:
|
|
918
|
+
transform(cellInfo, formula, rule) {
|
|
919
|
+
const { value: cellValue } = cellInfo;
|
|
903
920
|
return {
|
|
904
|
-
...
|
|
905
|
-
value:
|
|
921
|
+
...cellInfo,
|
|
922
|
+
value: getCellValueNumber(cellValue)
|
|
906
923
|
};
|
|
907
924
|
}
|
|
908
|
-
_parseNumber(
|
|
909
|
-
return
|
|
925
|
+
_parseNumber(formula) {
|
|
926
|
+
return formula == null ? Number.NaN : +formula;
|
|
910
927
|
}
|
|
911
|
-
async parseFormula(
|
|
912
|
-
const
|
|
928
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
929
|
+
const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, isFormulaValid = isLegalFormulaResult(String(formulaResult1 == null ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 == null ? void 0 : formulaResult2.v));
|
|
913
930
|
return {
|
|
914
|
-
formula1: this._parseNumber(
|
|
915
|
-
formula2: this._parseNumber(
|
|
916
|
-
isFormulaValid
|
|
931
|
+
formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 == null ? void 0 : formulaResult1.v : formula1),
|
|
932
|
+
formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 == null ? void 0 : formulaResult2.v : formula2),
|
|
933
|
+
isFormulaValid
|
|
917
934
|
};
|
|
918
935
|
}
|
|
919
|
-
validatorFormula(
|
|
920
|
-
const
|
|
921
|
-
if (!
|
|
936
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
937
|
+
const operator = rule.operator;
|
|
938
|
+
if (!operator)
|
|
922
939
|
return {
|
|
923
940
|
success: !1
|
|
924
941
|
};
|
|
925
|
-
const
|
|
926
|
-
return
|
|
927
|
-
success:
|
|
928
|
-
formula1:
|
|
929
|
-
formula2:
|
|
942
|
+
const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrNumber(rule.formula1), formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrNumber(rule.formula2), isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator), errorMsg = this.localeService.t("dataValidation.validFail.number");
|
|
943
|
+
return isTwoFormula ? {
|
|
944
|
+
success: formula1Success && formula2Success,
|
|
945
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
946
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
930
947
|
} : {
|
|
931
|
-
success:
|
|
932
|
-
formula1:
|
|
948
|
+
success: formula1Success,
|
|
949
|
+
formula1: formula1Success ? "" : errorMsg
|
|
933
950
|
};
|
|
934
951
|
}
|
|
935
|
-
generateRuleErrorMessage(
|
|
936
|
-
if (!
|
|
952
|
+
generateRuleErrorMessage(rule, position) {
|
|
953
|
+
if (!rule.operator)
|
|
937
954
|
return this.titleStr;
|
|
938
|
-
const { transformedFormula1
|
|
939
|
-
return `${this.localeService.t(
|
|
955
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
|
|
956
|
+
return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
|
|
940
957
|
}
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
|
|
958
|
+
};
|
|
959
|
+
__name(_DecimalValidator, "DecimalValidator");
|
|
960
|
+
let DecimalValidator = _DecimalValidator;
|
|
961
|
+
function getRuleFormulaResultSet(result) {
|
|
962
|
+
if (!result)
|
|
944
963
|
return [];
|
|
945
|
-
const
|
|
946
|
-
return
|
|
947
|
-
(
|
|
948
|
-
|
|
949
|
-
var
|
|
950
|
-
const
|
|
951
|
-
if (
|
|
952
|
-
if (typeof
|
|
953
|
-
|
|
964
|
+
const resultSet = /* @__PURE__ */ new Set();
|
|
965
|
+
return result.forEach(
|
|
966
|
+
(row) => {
|
|
967
|
+
row.forEach((cell) => {
|
|
968
|
+
var _a12, _b;
|
|
969
|
+
const value = getCellValueOrigin(cell);
|
|
970
|
+
if (value != null) {
|
|
971
|
+
if (typeof value != "string" && typeof (cell == null ? void 0 : cell.s) == "object" && ((_b = (_a12 = cell.s) == null ? void 0 : _a12.n) != null && _b.pattern)) {
|
|
972
|
+
resultSet.add(numfmt.format(cell.s.n.pattern, value, { throws: !1 }));
|
|
954
973
|
return;
|
|
955
974
|
}
|
|
956
|
-
|
|
975
|
+
isLegalFormulaResult(value.toString()) && resultSet.add(value.toString());
|
|
957
976
|
}
|
|
958
977
|
});
|
|
959
978
|
}
|
|
960
|
-
), [...
|
|
979
|
+
), [...resultSet];
|
|
961
980
|
}
|
|
962
|
-
|
|
981
|
+
__name(getRuleFormulaResultSet, "getRuleFormulaResultSet");
|
|
982
|
+
const supportedFormula = [
|
|
963
983
|
"if",
|
|
964
984
|
"indirect",
|
|
965
985
|
"choose",
|
|
966
986
|
"offset"
|
|
967
987
|
];
|
|
968
|
-
function
|
|
969
|
-
if (!
|
|
988
|
+
function isValidListFormula(formula, lexer) {
|
|
989
|
+
if (!isFormulaString(formula) || isReferenceString(formula.slice(1)))
|
|
970
990
|
return !0;
|
|
971
|
-
const
|
|
972
|
-
return
|
|
991
|
+
const nodes = lexer.sequenceNodesBuilder(formula);
|
|
992
|
+
return nodes && nodes.some((node) => typeof node == "object" && node.nodeType === sequenceNodeType.FUNCTION && supportedFormula.indexOf(node.token.toLowerCase()) > -1);
|
|
973
993
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
994
|
+
__name(isValidListFormula, "isValidListFormula");
|
|
995
|
+
function isRuleIntersects(rule, sheetName) {
|
|
996
|
+
const { formula1 = "", ranges } = rule;
|
|
997
|
+
if (isReferenceString(formula1.slice(1))) {
|
|
998
|
+
const refRange = deserializeRangeWithSheet(formula1.slice(1));
|
|
999
|
+
if ((!refRange.sheetName || refRange.sheetName === sheetName) && ranges.some((range) => Rectangle.intersects(range, refRange.range)))
|
|
979
1000
|
return !0;
|
|
980
1001
|
}
|
|
981
1002
|
return !1;
|
|
982
1003
|
}
|
|
983
|
-
|
|
1004
|
+
__name(isRuleIntersects, "isRuleIntersects");
|
|
1005
|
+
const _ListValidator = class _ListValidator extends BaseDataValidator {
|
|
984
1006
|
constructor() {
|
|
985
1007
|
super(...arguments);
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
}
|
|
996
|
-
validatorFormula(
|
|
997
|
-
var
|
|
998
|
-
const
|
|
1008
|
+
__publicField(this, "formulaService", this.injector.get(DataValidationFormulaService));
|
|
1009
|
+
__publicField(this, "_lexer", this.injector.get(LexerTreeBuilder));
|
|
1010
|
+
__publicField(this, "_univerInstanceService", this.injector.get(IUniverInstanceService));
|
|
1011
|
+
__publicField(this, "offsetFormulaByRange", !1);
|
|
1012
|
+
__publicField(this, "id", DataValidationType.LIST);
|
|
1013
|
+
__publicField(this, "title", "dataValidation.list.title");
|
|
1014
|
+
__publicField(this, "operators", []);
|
|
1015
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
1016
|
+
__publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name((rule) => rule.renderMode !== DataValidationRenderMode.TEXT, "skipDefaultFontRender"));
|
|
1017
|
+
}
|
|
1018
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
1019
|
+
var _a12, _b, _c;
|
|
1020
|
+
const success = !Tools.isBlank(rule.formula1), valid = isValidListFormula((_a12 = rule.formula1) != null ? _a12 : "", this._lexer), sheetName = (_c = (_b = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _b.getSheetBySheetId(subUnitId)) == null ? void 0 : _c.getName(), isIntersects = isRuleIntersects(rule, sheetName != null ? sheetName : "");
|
|
999
1021
|
return {
|
|
1000
|
-
success: !!(
|
|
1001
|
-
formula1:
|
|
1022
|
+
success: !!(success && valid && !isIntersects),
|
|
1023
|
+
formula1: success ? valid ? isIntersects ? this.localeService.t("dataValidation.validFail.listIntersects") : void 0 : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
|
|
1002
1024
|
};
|
|
1003
1025
|
}
|
|
1004
|
-
getExtraStyle(
|
|
1005
|
-
var
|
|
1006
|
-
const
|
|
1007
|
-
if (
|
|
1008
|
-
const
|
|
1009
|
-
if (
|
|
1026
|
+
getExtraStyle(rule, value, { style: defaultStyle }) {
|
|
1027
|
+
var _a12;
|
|
1028
|
+
const tb = (_a12 = defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) != null ? _a12 : WrapStrategy.WRAP;
|
|
1029
|
+
if (rule.type === DataValidationType.LIST && (rule.renderMode === DataValidationRenderMode.ARROW || rule.renderMode === DataValidationRenderMode.TEXT)) {
|
|
1030
|
+
const colorMap = this.getListWithColorMap(rule), valueStr = `${value != null ? value : ""}`, color = colorMap[valueStr];
|
|
1031
|
+
if (color)
|
|
1010
1032
|
return {
|
|
1011
1033
|
bg: {
|
|
1012
|
-
rgb:
|
|
1034
|
+
rgb: color
|
|
1013
1035
|
},
|
|
1014
|
-
tb
|
|
1036
|
+
tb
|
|
1015
1037
|
};
|
|
1016
1038
|
}
|
|
1017
1039
|
return {
|
|
1018
|
-
tb
|
|
1040
|
+
tb
|
|
1019
1041
|
};
|
|
1020
1042
|
}
|
|
1021
|
-
parseCellValue(
|
|
1022
|
-
const
|
|
1023
|
-
return
|
|
1043
|
+
parseCellValue(cellValue) {
|
|
1044
|
+
const cellString = cellValue.toString();
|
|
1045
|
+
return deserializeListOptions(cellString);
|
|
1024
1046
|
}
|
|
1025
|
-
async parseFormula(
|
|
1026
|
-
var
|
|
1027
|
-
const
|
|
1047
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
1048
|
+
var _a12, _b;
|
|
1049
|
+
const results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), formulaResult1 = getFormulaResult((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]);
|
|
1028
1050
|
return {
|
|
1029
1051
|
formula1: void 0,
|
|
1030
1052
|
formula2: void 0,
|
|
1031
|
-
isFormulaValid:
|
|
1053
|
+
isFormulaValid: isLegalFormulaResult(String(formulaResult1))
|
|
1032
1054
|
};
|
|
1033
1055
|
}
|
|
1034
|
-
async isValidType(
|
|
1035
|
-
var
|
|
1036
|
-
const { value
|
|
1037
|
-
return this.parseCellValue(
|
|
1056
|
+
async isValidType(cellInfo, formula, rule) {
|
|
1057
|
+
var _a12, _b;
|
|
1058
|
+
const { value, unitId, subUnitId } = cellInfo, { formula1 = "" } = rule, results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), formula1Result = isFormulaString(formula1) ? getRuleFormulaResultSet((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]) : deserializeListOptions(formula1);
|
|
1059
|
+
return this.parseCellValue(value).every((i) => formula1Result.includes(i));
|
|
1038
1060
|
}
|
|
1039
1061
|
generateRuleName() {
|
|
1040
1062
|
return this.localeService.t("dataValidation.list.name");
|
|
@@ -1042,1366 +1064,1383 @@ class mt extends k {
|
|
|
1042
1064
|
generateRuleErrorMessage() {
|
|
1043
1065
|
return this.localeService.t("dataValidation.list.error");
|
|
1044
1066
|
}
|
|
1045
|
-
getList(
|
|
1046
|
-
var
|
|
1047
|
-
const { formula1
|
|
1048
|
-
if (!
|
|
1049
|
-
const
|
|
1050
|
-
if (!
|
|
1051
|
-
const
|
|
1052
|
-
return
|
|
1053
|
-
}
|
|
1054
|
-
async getListAsync(
|
|
1055
|
-
var
|
|
1056
|
-
const { formula1
|
|
1057
|
-
if (!
|
|
1058
|
-
const
|
|
1059
|
-
if (!
|
|
1060
|
-
const
|
|
1061
|
-
return
|
|
1062
|
-
}
|
|
1063
|
-
getListWithColor(
|
|
1064
|
-
const
|
|
1065
|
-
return
|
|
1066
|
-
}
|
|
1067
|
-
getListWithColorMap(
|
|
1068
|
-
const
|
|
1069
|
-
return
|
|
1070
|
-
|
|
1071
|
-
}),
|
|
1067
|
+
getList(rule, currentUnitId, currentSubUnitId) {
|
|
1068
|
+
var _a12, _b, _c, _d;
|
|
1069
|
+
const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (_a12 = currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : void 0) != null ? _a12 : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
1070
|
+
if (!workbook) return [];
|
|
1071
|
+
const worksheet = (_b = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) != null ? _b : workbook.getActiveSheet();
|
|
1072
|
+
if (!worksheet) return [];
|
|
1073
|
+
const unitId = workbook.getUnitId(), subUnitId = worksheet.getSheetId(), results = this.formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
|
|
1074
|
+
return isFormulaString(formula1) ? getRuleFormulaResultSet((_d = (_c = results == null ? void 0 : results[0]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : deserializeListOptions(formula1);
|
|
1075
|
+
}
|
|
1076
|
+
async getListAsync(rule, currentUnitId, currentSubUnitId) {
|
|
1077
|
+
var _a12, _b, _c, _d;
|
|
1078
|
+
const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (_a12 = currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : void 0) != null ? _a12 : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
1079
|
+
if (!workbook) return [];
|
|
1080
|
+
const worksheet = (_b = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) != null ? _b : workbook.getActiveSheet();
|
|
1081
|
+
if (!worksheet) return [];
|
|
1082
|
+
const unitId = workbook.getUnitId(), subUnitId = worksheet.getSheetId(), results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
|
|
1083
|
+
return isFormulaString(formula1) ? getRuleFormulaResultSet((_d = (_c = results == null ? void 0 : results[0]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : deserializeListOptions(formula1);
|
|
1084
|
+
}
|
|
1085
|
+
getListWithColor(rule, currentUnitId, currentSubUnitId) {
|
|
1086
|
+
const list = this.getList(rule, currentUnitId, currentSubUnitId), colorList = (rule.formula2 || "").split(",");
|
|
1087
|
+
return list.map((label, i) => ({ label, color: colorList[i] }));
|
|
1088
|
+
}
|
|
1089
|
+
getListWithColorMap(rule, currentUnitId, currentSubUnitId) {
|
|
1090
|
+
const list = this.getListWithColor(rule, currentUnitId, currentSubUnitId), map = {};
|
|
1091
|
+
return list.forEach((item) => {
|
|
1092
|
+
item.color && (map[item.label] = item.color);
|
|
1093
|
+
}), map;
|
|
1072
1094
|
}
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1095
|
+
};
|
|
1096
|
+
__name(_ListValidator, "ListValidator");
|
|
1097
|
+
let ListValidator = _ListValidator;
|
|
1098
|
+
const _TextLengthValidator = class _TextLengthValidator extends BaseDataValidator {
|
|
1075
1099
|
constructor() {
|
|
1076
1100
|
super(...arguments);
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1101
|
+
__publicField(this, "id", DataValidationType.TEXT_LENGTH);
|
|
1102
|
+
__publicField(this, "title", "dataValidation.textLength.title");
|
|
1103
|
+
__publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
|
|
1104
|
+
__publicField(this, "operators", [
|
|
1105
|
+
DataValidationOperator.BETWEEN,
|
|
1106
|
+
DataValidationOperator.EQUAL,
|
|
1107
|
+
DataValidationOperator.GREATER_THAN,
|
|
1108
|
+
DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
1109
|
+
DataValidationOperator.LESS_THAN,
|
|
1110
|
+
DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
1111
|
+
DataValidationOperator.NOT_BETWEEN,
|
|
1112
|
+
DataValidationOperator.NOT_EQUAL
|
|
1089
1113
|
]);
|
|
1090
|
-
|
|
1091
|
-
|
|
1114
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
1115
|
+
__publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
1092
1116
|
}
|
|
1093
|
-
_isFormulaOrInt(
|
|
1094
|
-
return !
|
|
1117
|
+
_isFormulaOrInt(formula) {
|
|
1118
|
+
return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula) && Number.isInteger(+formula));
|
|
1095
1119
|
}
|
|
1096
|
-
validatorFormula(
|
|
1097
|
-
const
|
|
1098
|
-
if (!
|
|
1120
|
+
validatorFormula(rule, _unitId, _subUnitId) {
|
|
1121
|
+
const operator = rule.operator;
|
|
1122
|
+
if (!operator)
|
|
1099
1123
|
return {
|
|
1100
1124
|
success: !1
|
|
1101
1125
|
};
|
|
1102
|
-
const
|
|
1103
|
-
return
|
|
1104
|
-
success:
|
|
1105
|
-
formula1:
|
|
1106
|
-
formula2:
|
|
1126
|
+
const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1), formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2), isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator), errorMsg = this.localeService.t("dataValidation.validFail.number");
|
|
1127
|
+
return isTwoFormula ? {
|
|
1128
|
+
success: formula1Success && formula2Success,
|
|
1129
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
1130
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
1107
1131
|
} : {
|
|
1108
|
-
success:
|
|
1109
|
-
formula1:
|
|
1132
|
+
success: formula1Success,
|
|
1133
|
+
formula1: errorMsg
|
|
1110
1134
|
};
|
|
1111
1135
|
}
|
|
1112
|
-
_parseNumber(
|
|
1113
|
-
return
|
|
1136
|
+
_parseNumber(formula) {
|
|
1137
|
+
return formula == null ? Number.NaN : +formula;
|
|
1114
1138
|
}
|
|
1115
|
-
async parseFormula(
|
|
1116
|
-
const
|
|
1139
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
1140
|
+
const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, isFormulaValid = isLegalFormulaResult(String(formulaResult1 == null ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 == null ? void 0 : formulaResult2.v));
|
|
1117
1141
|
return {
|
|
1118
|
-
formula1: this._parseNumber(
|
|
1119
|
-
formula2: this._parseNumber(
|
|
1120
|
-
isFormulaValid
|
|
1142
|
+
formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 == null ? void 0 : formulaResult1.v : formula1),
|
|
1143
|
+
formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 == null ? void 0 : formulaResult2.v : formula2),
|
|
1144
|
+
isFormulaValid
|
|
1121
1145
|
};
|
|
1122
1146
|
}
|
|
1123
|
-
transform(
|
|
1147
|
+
transform(cellInfo, _formula, _rule) {
|
|
1124
1148
|
return {
|
|
1125
|
-
...
|
|
1126
|
-
value:
|
|
1149
|
+
...cellInfo,
|
|
1150
|
+
value: cellInfo.value.toString().length
|
|
1127
1151
|
};
|
|
1128
1152
|
}
|
|
1129
|
-
async isValidType(
|
|
1130
|
-
const { value:
|
|
1131
|
-
return typeof
|
|
1153
|
+
async isValidType(cellInfo, _formula, _rule) {
|
|
1154
|
+
const { value: cellValue } = cellInfo;
|
|
1155
|
+
return typeof cellValue == "string" || typeof cellValue == "number";
|
|
1132
1156
|
}
|
|
1133
|
-
generateRuleErrorMessage(
|
|
1134
|
-
if (!
|
|
1157
|
+
generateRuleErrorMessage(rule, pos) {
|
|
1158
|
+
if (!rule.operator)
|
|
1135
1159
|
return this.titleStr;
|
|
1136
|
-
const { transformedFormula1
|
|
1137
|
-
return `${this.localeService.t(
|
|
1160
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
|
|
1161
|
+
return `${this.localeService.t(TextLengthErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
|
|
1138
1162
|
}
|
|
1163
|
+
};
|
|
1164
|
+
__name(_TextLengthValidator, "TextLengthValidator");
|
|
1165
|
+
let TextLengthValidator = _TextLengthValidator;
|
|
1166
|
+
function isBlankCell(cellData) {
|
|
1167
|
+
var _a12, _b;
|
|
1168
|
+
return cellData ? cellData.p ? !((_b = (_a12 = cellData.p.body) == null ? void 0 : _a12.dataStream) != null ? _b : "").slice(0, -2).trim() : Tools.isBlank(cellData.v) : !0;
|
|
1139
1169
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
function be(s, a, e, t, r = "command", i = !0) {
|
|
1145
|
-
const o = t.get(Z), n = t.get(G), l = [], u = [], d = t.get(F), c = t.get(O), m = Ye(c, { unitId: s, subUnitId: a });
|
|
1146
|
-
if (!m)
|
|
1170
|
+
__name(isBlankCell, "isBlankCell");
|
|
1171
|
+
function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, source = "command", fillDefaultValue = !0) {
|
|
1172
|
+
const lexerTreeBuilder = accessor.get(LexerTreeBuilder), validatorRegistryService = accessor.get(DataValidatorRegistryService), redoMutations = [], undoMutations = [], sheetDataValidationModel = accessor.get(SheetDataValidationModel), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
|
|
1173
|
+
if (!target)
|
|
1147
1174
|
return {
|
|
1148
|
-
redoMutations
|
|
1149
|
-
undoMutations
|
|
1175
|
+
redoMutations,
|
|
1176
|
+
undoMutations
|
|
1150
1177
|
};
|
|
1151
|
-
const { worksheet
|
|
1152
|
-
let
|
|
1153
|
-
function
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
const
|
|
1157
|
-
(
|
|
1158
|
-
v:
|
|
1178
|
+
const { worksheet } = target, redoMatrix = new ObjectMatrix();
|
|
1179
|
+
let setRangeValue = !1;
|
|
1180
|
+
function setRangesDefaultValue(ranges, defaultValue) {
|
|
1181
|
+
fillDefaultValue && ranges.forEach((range) => {
|
|
1182
|
+
Range.foreach(range, (row, column) => {
|
|
1183
|
+
const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
|
|
1184
|
+
(isBlankCell(cellData) || value === defaultValue) && !(cellData != null && cellData.p) && (setRangeValue = !0, redoMatrix.setValue(row, column, {
|
|
1185
|
+
v: defaultValue,
|
|
1159
1186
|
p: null
|
|
1160
1187
|
}));
|
|
1161
1188
|
});
|
|
1162
1189
|
});
|
|
1163
1190
|
}
|
|
1164
|
-
if (
|
|
1165
|
-
switch (
|
|
1191
|
+
if (__name(setRangesDefaultValue, "setRangesDefaultValue"), diffs.forEach((diff) => {
|
|
1192
|
+
switch (diff.type) {
|
|
1166
1193
|
case "delete":
|
|
1167
|
-
|
|
1168
|
-
id:
|
|
1194
|
+
redoMutations.push({
|
|
1195
|
+
id: RemoveDataValidationMutation.id,
|
|
1169
1196
|
params: {
|
|
1170
|
-
unitId
|
|
1171
|
-
subUnitId
|
|
1172
|
-
ruleId:
|
|
1173
|
-
source
|
|
1197
|
+
unitId,
|
|
1198
|
+
subUnitId,
|
|
1199
|
+
ruleId: diff.rule.uid,
|
|
1200
|
+
source
|
|
1174
1201
|
}
|
|
1175
|
-
}),
|
|
1176
|
-
id:
|
|
1202
|
+
}), undoMutations.unshift({
|
|
1203
|
+
id: AddDataValidationMutation.id,
|
|
1177
1204
|
params: {
|
|
1178
|
-
unitId
|
|
1179
|
-
subUnitId
|
|
1180
|
-
rule:
|
|
1181
|
-
index:
|
|
1182
|
-
source
|
|
1205
|
+
unitId,
|
|
1206
|
+
subUnitId,
|
|
1207
|
+
rule: diff.rule,
|
|
1208
|
+
index: diff.index,
|
|
1209
|
+
source
|
|
1183
1210
|
}
|
|
1184
1211
|
});
|
|
1185
1212
|
break;
|
|
1186
1213
|
case "update": {
|
|
1187
|
-
if (
|
|
1188
|
-
const
|
|
1189
|
-
|
|
1190
|
-
id:
|
|
1214
|
+
if (shouldOffsetFormulaByRange(diff.rule.type, validatorRegistryService)) {
|
|
1215
|
+
const originRow = diff.oldRanges[0].startRow, originColumn = diff.oldRanges[0].startColumn, newRow = diff.newRanges[0].startRow, newColumn = diff.newRanges[0].startColumn, rowDiff = newRow - originRow, columnDiff = newColumn - originColumn, newFormula = isFormulaString(diff.rule.formula1) ? lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula1, columnDiff, rowDiff) : diff.rule.formula1, newFormula2 = isFormulaString(diff.rule.formula2) ? lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula2, columnDiff, rowDiff) : diff.rule.formula2;
|
|
1216
|
+
newFormula !== diff.rule.formula1 || newFormula2 !== diff.rule.formula2 || !isRangesEqual(diff.newRanges, diff.oldRanges) ? (redoMutations.push({
|
|
1217
|
+
id: UpdateDataValidationMutation.id,
|
|
1191
1218
|
params: {
|
|
1192
|
-
unitId
|
|
1193
|
-
subUnitId
|
|
1194
|
-
ruleId:
|
|
1219
|
+
unitId,
|
|
1220
|
+
subUnitId,
|
|
1221
|
+
ruleId: diff.ruleId,
|
|
1195
1222
|
payload: {
|
|
1196
|
-
type:
|
|
1223
|
+
type: UpdateRuleType.ALL,
|
|
1197
1224
|
payload: {
|
|
1198
|
-
formula1:
|
|
1199
|
-
formula2:
|
|
1200
|
-
ranges:
|
|
1225
|
+
formula1: newFormula,
|
|
1226
|
+
formula2: newFormula2,
|
|
1227
|
+
ranges: diff.newRanges
|
|
1201
1228
|
}
|
|
1202
1229
|
}
|
|
1203
1230
|
}
|
|
1204
|
-
}),
|
|
1205
|
-
id:
|
|
1231
|
+
}), undoMutations.unshift({
|
|
1232
|
+
id: UpdateDataValidationMutation.id,
|
|
1206
1233
|
params: {
|
|
1207
|
-
unitId
|
|
1208
|
-
subUnitId
|
|
1209
|
-
ruleId:
|
|
1234
|
+
unitId,
|
|
1235
|
+
subUnitId,
|
|
1236
|
+
ruleId: diff.ruleId,
|
|
1210
1237
|
payload: {
|
|
1211
|
-
type:
|
|
1238
|
+
type: UpdateRuleType.ALL,
|
|
1212
1239
|
payload: {
|
|
1213
|
-
formula1:
|
|
1214
|
-
formula2:
|
|
1215
|
-
ranges:
|
|
1240
|
+
formula1: diff.rule.formula1,
|
|
1241
|
+
formula2: diff.rule.formula2,
|
|
1242
|
+
ranges: diff.oldRanges
|
|
1216
1243
|
}
|
|
1217
1244
|
}
|
|
1218
1245
|
}
|
|
1219
|
-
})) : (
|
|
1220
|
-
id:
|
|
1246
|
+
})) : (redoMutations.push({
|
|
1247
|
+
id: UpdateDataValidationMutation.id,
|
|
1221
1248
|
params: {
|
|
1222
|
-
unitId
|
|
1223
|
-
subUnitId
|
|
1224
|
-
ruleId:
|
|
1249
|
+
unitId,
|
|
1250
|
+
subUnitId,
|
|
1251
|
+
ruleId: diff.ruleId,
|
|
1225
1252
|
payload: {
|
|
1226
|
-
type:
|
|
1227
|
-
payload:
|
|
1253
|
+
type: UpdateRuleType.RANGE,
|
|
1254
|
+
payload: diff.newRanges
|
|
1228
1255
|
},
|
|
1229
|
-
source
|
|
1256
|
+
source
|
|
1230
1257
|
}
|
|
1231
|
-
}),
|
|
1232
|
-
id:
|
|
1258
|
+
}), undoMutations.unshift({
|
|
1259
|
+
id: UpdateDataValidationMutation.id,
|
|
1233
1260
|
params: {
|
|
1234
|
-
unitId
|
|
1235
|
-
subUnitId
|
|
1236
|
-
ruleId:
|
|
1261
|
+
unitId,
|
|
1262
|
+
subUnitId,
|
|
1263
|
+
ruleId: diff.ruleId,
|
|
1237
1264
|
payload: {
|
|
1238
|
-
type:
|
|
1239
|
-
payload:
|
|
1265
|
+
type: UpdateRuleType.RANGE,
|
|
1266
|
+
payload: diff.oldRanges
|
|
1240
1267
|
},
|
|
1241
|
-
source
|
|
1268
|
+
source
|
|
1242
1269
|
}
|
|
1243
1270
|
}));
|
|
1244
1271
|
} else
|
|
1245
|
-
|
|
1246
|
-
id:
|
|
1272
|
+
redoMutations.push({
|
|
1273
|
+
id: UpdateDataValidationMutation.id,
|
|
1247
1274
|
params: {
|
|
1248
|
-
unitId
|
|
1249
|
-
subUnitId
|
|
1250
|
-
ruleId:
|
|
1275
|
+
unitId,
|
|
1276
|
+
subUnitId,
|
|
1277
|
+
ruleId: diff.ruleId,
|
|
1251
1278
|
payload: {
|
|
1252
|
-
type:
|
|
1253
|
-
payload:
|
|
1279
|
+
type: UpdateRuleType.RANGE,
|
|
1280
|
+
payload: diff.newRanges
|
|
1254
1281
|
},
|
|
1255
|
-
source
|
|
1282
|
+
source
|
|
1256
1283
|
}
|
|
1257
|
-
}),
|
|
1258
|
-
id:
|
|
1284
|
+
}), undoMutations.unshift({
|
|
1285
|
+
id: UpdateDataValidationMutation.id,
|
|
1259
1286
|
params: {
|
|
1260
|
-
unitId
|
|
1261
|
-
subUnitId
|
|
1262
|
-
ruleId:
|
|
1287
|
+
unitId,
|
|
1288
|
+
subUnitId,
|
|
1289
|
+
ruleId: diff.ruleId,
|
|
1263
1290
|
payload: {
|
|
1264
|
-
type:
|
|
1265
|
-
payload:
|
|
1291
|
+
type: UpdateRuleType.RANGE,
|
|
1292
|
+
payload: diff.oldRanges
|
|
1266
1293
|
},
|
|
1267
|
-
source
|
|
1294
|
+
source
|
|
1268
1295
|
}
|
|
1269
1296
|
});
|
|
1270
|
-
const
|
|
1271
|
-
if (
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1297
|
+
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, diff.ruleId);
|
|
1298
|
+
if (rule && rule.type === DataValidationType.CHECKBOX) {
|
|
1299
|
+
const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(rule, unitId, subUnitId);
|
|
1300
|
+
setRangesDefaultValue(diff.newRanges, formula.formula2);
|
|
1274
1301
|
}
|
|
1275
1302
|
break;
|
|
1276
1303
|
}
|
|
1277
1304
|
case "add": {
|
|
1278
|
-
if (
|
|
1279
|
-
id:
|
|
1305
|
+
if (redoMutations.push({
|
|
1306
|
+
id: AddDataValidationMutation.id,
|
|
1280
1307
|
params: {
|
|
1281
|
-
unitId
|
|
1282
|
-
subUnitId
|
|
1283
|
-
rule:
|
|
1284
|
-
source
|
|
1308
|
+
unitId,
|
|
1309
|
+
subUnitId,
|
|
1310
|
+
rule: diff.rule,
|
|
1311
|
+
source
|
|
1285
1312
|
}
|
|
1286
|
-
}),
|
|
1287
|
-
id:
|
|
1313
|
+
}), undoMutations.unshift({
|
|
1314
|
+
id: RemoveDataValidationMutation.id,
|
|
1288
1315
|
params: {
|
|
1289
|
-
unitId
|
|
1290
|
-
subUnitId
|
|
1291
|
-
ruleId:
|
|
1292
|
-
source
|
|
1316
|
+
unitId,
|
|
1317
|
+
subUnitId,
|
|
1318
|
+
ruleId: diff.rule.uid,
|
|
1319
|
+
source
|
|
1293
1320
|
}
|
|
1294
|
-
}),
|
|
1295
|
-
const
|
|
1296
|
-
|
|
1321
|
+
}), diff.rule.type === DataValidationType.CHECKBOX) {
|
|
1322
|
+
const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
|
|
1323
|
+
setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
|
|
1297
1324
|
}
|
|
1298
1325
|
break;
|
|
1299
1326
|
}
|
|
1300
1327
|
}
|
|
1301
|
-
}),
|
|
1302
|
-
const
|
|
1303
|
-
id:
|
|
1328
|
+
}), setRangeValue) {
|
|
1329
|
+
const redoSetRangeValues = {
|
|
1330
|
+
id: SetRangeValuesMutation.id,
|
|
1304
1331
|
params: {
|
|
1305
|
-
unitId
|
|
1306
|
-
subUnitId
|
|
1307
|
-
cellValue:
|
|
1332
|
+
unitId,
|
|
1333
|
+
subUnitId,
|
|
1334
|
+
cellValue: redoMatrix.getData()
|
|
1308
1335
|
}
|
|
1309
|
-
},
|
|
1310
|
-
id:
|
|
1311
|
-
params:
|
|
1336
|
+
}, undoSetRangeValues = {
|
|
1337
|
+
id: SetRangeValuesMutation.id,
|
|
1338
|
+
params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
|
|
1312
1339
|
};
|
|
1313
|
-
|
|
1340
|
+
redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues);
|
|
1314
1341
|
}
|
|
1315
1342
|
return {
|
|
1316
|
-
redoMutations
|
|
1317
|
-
undoMutations
|
|
1343
|
+
redoMutations,
|
|
1344
|
+
undoMutations
|
|
1318
1345
|
};
|
|
1319
1346
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1347
|
+
__name(getDataValidationDiffMutations, "getDataValidationDiffMutations");
|
|
1348
|
+
const UpdateSheetDataValidationRangeCommand = {
|
|
1349
|
+
type: CommandType.COMMAND,
|
|
1322
1350
|
id: "sheet.command.updateDataValidationRuleRange",
|
|
1323
|
-
handler(
|
|
1324
|
-
if (!
|
|
1351
|
+
handler(accessor, params) {
|
|
1352
|
+
if (!params)
|
|
1325
1353
|
return !1;
|
|
1326
|
-
const { unitId
|
|
1327
|
-
if (!
|
|
1354
|
+
const { unitId, subUnitId, ranges, ruleId } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService);
|
|
1355
|
+
if (!sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId))
|
|
1328
1356
|
return !1;
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1331
|
-
const
|
|
1332
|
-
return
|
|
1333
|
-
undoMutations
|
|
1334
|
-
redoMutations
|
|
1335
|
-
unitID:
|
|
1336
|
-
}),
|
|
1337
|
-
}
|
|
1338
|
-
},
|
|
1339
|
-
type:
|
|
1357
|
+
const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1358
|
+
matrix.updateRange(ruleId, ranges);
|
|
1359
|
+
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
1360
|
+
return undoRedoService.pushUndoRedo({
|
|
1361
|
+
undoMutations,
|
|
1362
|
+
redoMutations,
|
|
1363
|
+
unitID: unitId
|
|
1364
|
+
}), sequenceExecute(redoMutations, commandService), !0;
|
|
1365
|
+
}
|
|
1366
|
+
}, AddSheetDataValidationCommand = {
|
|
1367
|
+
type: CommandType.COMMAND,
|
|
1340
1368
|
id: "sheet.command.addDataValidation",
|
|
1341
|
-
handler(
|
|
1342
|
-
if (!
|
|
1369
|
+
handler(accessor, params) {
|
|
1370
|
+
if (!params)
|
|
1343
1371
|
return !1;
|
|
1344
|
-
const { unitId
|
|
1345
|
-
|
|
1346
|
-
const
|
|
1347
|
-
unitId
|
|
1348
|
-
subUnitId
|
|
1372
|
+
const { unitId, subUnitId, rule } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1373
|
+
matrix.addRule(rule);
|
|
1374
|
+
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), validator = sheetDataValidationModel.getValidator(rule.type), mutationParams = {
|
|
1375
|
+
unitId,
|
|
1376
|
+
subUnitId,
|
|
1349
1377
|
rule: {
|
|
1350
|
-
...
|
|
1351
|
-
...
|
|
1378
|
+
...rule,
|
|
1379
|
+
...validator == null ? void 0 : validator.normalizeFormula(rule, unitId, subUnitId)
|
|
1352
1380
|
}
|
|
1353
|
-
}, { redoMutations
|
|
1354
|
-
return
|
|
1355
|
-
id:
|
|
1356
|
-
params:
|
|
1357
|
-
}),
|
|
1358
|
-
id:
|
|
1381
|
+
}, { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
1382
|
+
return redoMutations.push({
|
|
1383
|
+
id: AddDataValidationMutation.id,
|
|
1384
|
+
params: mutationParams
|
|
1385
|
+
}), undoMutations.unshift({
|
|
1386
|
+
id: RemoveDataValidationMutation.id,
|
|
1359
1387
|
params: {
|
|
1360
|
-
unitId
|
|
1361
|
-
subUnitId
|
|
1362
|
-
ruleId:
|
|
1388
|
+
unitId,
|
|
1389
|
+
subUnitId,
|
|
1390
|
+
ruleId: rule.uid
|
|
1363
1391
|
}
|
|
1364
|
-
}),
|
|
1365
|
-
unitID:
|
|
1366
|
-
redoMutations
|
|
1367
|
-
undoMutations
|
|
1368
|
-
}),
|
|
1369
|
-
}
|
|
1370
|
-
},
|
|
1371
|
-
type:
|
|
1392
|
+
}), undoRedoService.pushUndoRedo({
|
|
1393
|
+
unitID: unitId,
|
|
1394
|
+
redoMutations,
|
|
1395
|
+
undoMutations
|
|
1396
|
+
}), sequenceExecute(redoMutations, commandService), !0;
|
|
1397
|
+
}
|
|
1398
|
+
}, UpdateSheetDataValidationSettingCommand = {
|
|
1399
|
+
type: CommandType.COMMAND,
|
|
1372
1400
|
id: "sheets.command.update-data-validation-setting",
|
|
1373
1401
|
// eslint-disable-next-line max-lines-per-function
|
|
1374
|
-
handler(
|
|
1375
|
-
if (!
|
|
1402
|
+
handler(accessor, params) {
|
|
1403
|
+
if (!params)
|
|
1376
1404
|
return !1;
|
|
1377
|
-
const
|
|
1378
|
-
if (!
|
|
1405
|
+
const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), dataValidatorRegistryService = accessor.get(DataValidatorRegistryService), { unitId, subUnitId, ruleId, setting } = params, validator = dataValidatorRegistryService.getValidatorItem(setting.type);
|
|
1406
|
+
if (!validator)
|
|
1379
1407
|
return !1;
|
|
1380
|
-
const
|
|
1381
|
-
if (!
|
|
1408
|
+
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1409
|
+
if (!rule)
|
|
1382
1410
|
return !1;
|
|
1383
|
-
const
|
|
1384
|
-
if (!
|
|
1411
|
+
const newRule = { ...rule, ...setting };
|
|
1412
|
+
if (!validator.validatorFormula(newRule, unitId, subUnitId).success)
|
|
1385
1413
|
return !1;
|
|
1386
|
-
const
|
|
1387
|
-
unitId
|
|
1388
|
-
subUnitId
|
|
1389
|
-
ruleId
|
|
1414
|
+
const mutationParams = {
|
|
1415
|
+
unitId,
|
|
1416
|
+
subUnitId,
|
|
1417
|
+
ruleId,
|
|
1390
1418
|
payload: {
|
|
1391
|
-
type:
|
|
1419
|
+
type: UpdateRuleType.SETTING,
|
|
1392
1420
|
payload: {
|
|
1393
|
-
...
|
|
1394
|
-
...
|
|
1421
|
+
...setting,
|
|
1422
|
+
...validator.normalizeFormula(newRule, unitId, subUnitId)
|
|
1395
1423
|
}
|
|
1396
1424
|
}
|
|
1397
|
-
},
|
|
1398
|
-
id:
|
|
1399
|
-
params:
|
|
1400
|
-
}],
|
|
1401
|
-
unitId
|
|
1402
|
-
subUnitId
|
|
1403
|
-
ruleId
|
|
1425
|
+
}, redoMutations = [{
|
|
1426
|
+
id: UpdateDataValidationMutation.id,
|
|
1427
|
+
params: mutationParams
|
|
1428
|
+
}], undoMutationParams = {
|
|
1429
|
+
unitId,
|
|
1430
|
+
subUnitId,
|
|
1431
|
+
ruleId,
|
|
1404
1432
|
payload: {
|
|
1405
|
-
type:
|
|
1406
|
-
payload:
|
|
1433
|
+
type: UpdateRuleType.SETTING,
|
|
1434
|
+
payload: getRuleSetting(rule)
|
|
1407
1435
|
}
|
|
1408
|
-
},
|
|
1409
|
-
id:
|
|
1410
|
-
params:
|
|
1436
|
+
}, undoMutations = [{
|
|
1437
|
+
id: UpdateDataValidationMutation.id,
|
|
1438
|
+
params: undoMutationParams
|
|
1411
1439
|
}];
|
|
1412
|
-
if (
|
|
1413
|
-
const
|
|
1414
|
-
if (
|
|
1415
|
-
const
|
|
1416
|
-
let
|
|
1417
|
-
if (
|
|
1418
|
-
|
|
1419
|
-
const
|
|
1420
|
-
(
|
|
1421
|
-
v:
|
|
1440
|
+
if (setting.type === DataValidationType.CHECKBOX) {
|
|
1441
|
+
const ranges = rule.ranges, univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
|
|
1442
|
+
if (target) {
|
|
1443
|
+
const redoMatrix = new ObjectMatrix(), { worksheet } = target, { formula2: oldFormula2 = CHECKBOX_FORMULA_2, formula1: oldFormula1 = CHECKBOX_FORMULA_1 } = rule, { formula2 = CHECKBOX_FORMULA_2, formula1 = CHECKBOX_FORMULA_1 } = setting;
|
|
1444
|
+
let setted = !1;
|
|
1445
|
+
if (ranges.forEach((range) => {
|
|
1446
|
+
Range.foreach(range, (row, column) => {
|
|
1447
|
+
const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
|
|
1448
|
+
(isBlankCell(cellData) || value === String(oldFormula2)) && !(cellData != null && cellData.p) ? (redoMatrix.setValue(row, column, {
|
|
1449
|
+
v: formula2,
|
|
1422
1450
|
p: null
|
|
1423
|
-
}),
|
|
1424
|
-
v:
|
|
1451
|
+
}), setted = !0) : value === String(oldFormula1) && !(cellData != null && cellData.p) && (redoMatrix.setValue(row, column, {
|
|
1452
|
+
v: formula1,
|
|
1425
1453
|
p: null
|
|
1426
|
-
}),
|
|
1454
|
+
}), setted = !0);
|
|
1427
1455
|
});
|
|
1428
|
-
}),
|
|
1429
|
-
const
|
|
1430
|
-
id:
|
|
1456
|
+
}), setted) {
|
|
1457
|
+
const redoSetRangeValues = {
|
|
1458
|
+
id: SetRangeValuesMutation.id,
|
|
1431
1459
|
params: {
|
|
1432
|
-
unitId
|
|
1433
|
-
subUnitId
|
|
1434
|
-
cellValue:
|
|
1460
|
+
unitId,
|
|
1461
|
+
subUnitId,
|
|
1462
|
+
cellValue: redoMatrix.getData()
|
|
1435
1463
|
}
|
|
1436
|
-
},
|
|
1437
|
-
id:
|
|
1438
|
-
params:
|
|
1464
|
+
}, undoSetRangeValues = {
|
|
1465
|
+
id: SetRangeValuesMutation.id,
|
|
1466
|
+
params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
|
|
1439
1467
|
};
|
|
1440
|
-
|
|
1468
|
+
redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues);
|
|
1441
1469
|
}
|
|
1442
1470
|
}
|
|
1443
1471
|
}
|
|
1444
|
-
return
|
|
1445
|
-
unitID:
|
|
1446
|
-
redoMutations
|
|
1447
|
-
undoMutations
|
|
1472
|
+
return sequenceExecute(redoMutations, commandService).result ? (redoUndoService.pushUndoRedo({
|
|
1473
|
+
unitID: unitId,
|
|
1474
|
+
redoMutations,
|
|
1475
|
+
undoMutations
|
|
1448
1476
|
}), !0) : !1;
|
|
1449
1477
|
}
|
|
1450
|
-
},
|
|
1451
|
-
type:
|
|
1478
|
+
}, UpdateSheetDataValidationOptionsCommand = {
|
|
1479
|
+
type: CommandType.COMMAND,
|
|
1452
1480
|
id: "sheets.command.update-data-validation-options",
|
|
1453
|
-
handler(
|
|
1454
|
-
if (!
|
|
1481
|
+
handler(accessor, params) {
|
|
1482
|
+
if (!params)
|
|
1455
1483
|
return !1;
|
|
1456
|
-
const
|
|
1457
|
-
if (!
|
|
1484
|
+
const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, options } = params, rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1485
|
+
if (!rule)
|
|
1458
1486
|
return !1;
|
|
1459
|
-
const
|
|
1460
|
-
unitId
|
|
1461
|
-
subUnitId
|
|
1462
|
-
ruleId
|
|
1487
|
+
const mutationParams = {
|
|
1488
|
+
unitId,
|
|
1489
|
+
subUnitId,
|
|
1490
|
+
ruleId,
|
|
1463
1491
|
payload: {
|
|
1464
|
-
type:
|
|
1465
|
-
payload:
|
|
1492
|
+
type: UpdateRuleType.OPTIONS,
|
|
1493
|
+
payload: options
|
|
1466
1494
|
}
|
|
1467
|
-
},
|
|
1468
|
-
id:
|
|
1469
|
-
params:
|
|
1470
|
-
}],
|
|
1471
|
-
unitId
|
|
1472
|
-
subUnitId
|
|
1473
|
-
ruleId
|
|
1495
|
+
}, redoMutations = [{
|
|
1496
|
+
id: UpdateDataValidationMutation.id,
|
|
1497
|
+
params: mutationParams
|
|
1498
|
+
}], undoMutationParams = {
|
|
1499
|
+
unitId,
|
|
1500
|
+
subUnitId,
|
|
1501
|
+
ruleId,
|
|
1474
1502
|
payload: {
|
|
1475
|
-
type:
|
|
1476
|
-
payload:
|
|
1503
|
+
type: UpdateRuleType.OPTIONS,
|
|
1504
|
+
payload: getRuleOptions(rule)
|
|
1477
1505
|
}
|
|
1478
|
-
},
|
|
1479
|
-
id:
|
|
1480
|
-
params:
|
|
1506
|
+
}, undoMutations = [{
|
|
1507
|
+
id: UpdateDataValidationMutation.id,
|
|
1508
|
+
params: undoMutationParams
|
|
1481
1509
|
}];
|
|
1482
|
-
return
|
|
1483
|
-
unitID:
|
|
1484
|
-
redoMutations
|
|
1485
|
-
undoMutations
|
|
1486
|
-
}),
|
|
1487
|
-
}
|
|
1488
|
-
},
|
|
1489
|
-
type:
|
|
1510
|
+
return redoUndoService.pushUndoRedo({
|
|
1511
|
+
unitID: unitId,
|
|
1512
|
+
redoMutations,
|
|
1513
|
+
undoMutations
|
|
1514
|
+
}), commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams), !0;
|
|
1515
|
+
}
|
|
1516
|
+
}, ClearRangeDataValidationCommand = {
|
|
1517
|
+
type: CommandType.COMMAND,
|
|
1490
1518
|
id: "sheets.command.clear-range-data-validation",
|
|
1491
|
-
handler(
|
|
1492
|
-
if (!
|
|
1519
|
+
handler(accessor, params) {
|
|
1520
|
+
if (!params)
|
|
1493
1521
|
return !1;
|
|
1494
|
-
const { unitId
|
|
1495
|
-
if (!
|
|
1496
|
-
const
|
|
1497
|
-
|
|
1498
|
-
const
|
|
1499
|
-
return
|
|
1500
|
-
unitID:
|
|
1501
|
-
redoMutations
|
|
1502
|
-
undoMutations
|
|
1503
|
-
}),
|
|
1504
|
-
}
|
|
1505
|
-
},
|
|
1506
|
-
type:
|
|
1522
|
+
const { unitId, subUnitId, ranges } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId }), sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1523
|
+
if (!target) return !1;
|
|
1524
|
+
const undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1525
|
+
matrix.removeRange(ranges);
|
|
1526
|
+
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
1527
|
+
return undoRedoService.pushUndoRedo({
|
|
1528
|
+
unitID: unitId,
|
|
1529
|
+
redoMutations,
|
|
1530
|
+
undoMutations
|
|
1531
|
+
}), sequenceExecute(redoMutations, commandService).result;
|
|
1532
|
+
}
|
|
1533
|
+
}, RemoveSheetAllDataValidationCommand = {
|
|
1534
|
+
type: CommandType.COMMAND,
|
|
1507
1535
|
id: "sheet.command.remove-all-data-validation",
|
|
1508
|
-
handler(
|
|
1509
|
-
if (!
|
|
1536
|
+
handler(accessor, params) {
|
|
1537
|
+
if (!params)
|
|
1510
1538
|
return !1;
|
|
1511
|
-
const { unitId
|
|
1512
|
-
unitId
|
|
1513
|
-
subUnitId
|
|
1514
|
-
ruleId:
|
|
1515
|
-
},
|
|
1516
|
-
id:
|
|
1517
|
-
params:
|
|
1518
|
-
}],
|
|
1519
|
-
id:
|
|
1539
|
+
const { unitId, subUnitId } = params, commandService = accessor.get(ICommandService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), undoRedoService = accessor.get(IUndoRedoService), currentRules = [...sheetDataValidationModel.getRules(unitId, subUnitId)], redoParams = {
|
|
1540
|
+
unitId,
|
|
1541
|
+
subUnitId,
|
|
1542
|
+
ruleId: currentRules.map((rule) => rule.uid)
|
|
1543
|
+
}, redoMutations = [{
|
|
1544
|
+
id: RemoveDataValidationMutation.id,
|
|
1545
|
+
params: redoParams
|
|
1546
|
+
}], undoMutations = [{
|
|
1547
|
+
id: AddDataValidationMutation.id,
|
|
1520
1548
|
params: {
|
|
1521
|
-
unitId
|
|
1522
|
-
subUnitId
|
|
1523
|
-
rule:
|
|
1549
|
+
unitId,
|
|
1550
|
+
subUnitId,
|
|
1551
|
+
rule: currentRules
|
|
1524
1552
|
}
|
|
1525
1553
|
}];
|
|
1526
|
-
return
|
|
1527
|
-
redoMutations
|
|
1528
|
-
undoMutations
|
|
1529
|
-
unitID:
|
|
1530
|
-
}),
|
|
1531
|
-
}
|
|
1532
|
-
},
|
|
1533
|
-
const
|
|
1534
|
-
if (Array.isArray(
|
|
1535
|
-
const
|
|
1554
|
+
return undoRedoService.pushUndoRedo({
|
|
1555
|
+
redoMutations,
|
|
1556
|
+
undoMutations,
|
|
1557
|
+
unitID: unitId
|
|
1558
|
+
}), commandService.executeCommand(RemoveDataValidationMutation.id, redoParams), !0;
|
|
1559
|
+
}
|
|
1560
|
+
}, removeDataValidationUndoFactory = /* @__PURE__ */ __name((accessor, redoParams) => {
|
|
1561
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, source } = redoParams;
|
|
1562
|
+
if (Array.isArray(ruleId)) {
|
|
1563
|
+
const rules = ruleId.map((id) => sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
1536
1564
|
return [{
|
|
1537
|
-
id:
|
|
1565
|
+
id: AddDataValidationMutation.id,
|
|
1538
1566
|
params: {
|
|
1539
|
-
unitId
|
|
1540
|
-
subUnitId
|
|
1541
|
-
rule:
|
|
1542
|
-
source
|
|
1567
|
+
unitId,
|
|
1568
|
+
subUnitId,
|
|
1569
|
+
rule: rules,
|
|
1570
|
+
source
|
|
1543
1571
|
}
|
|
1544
1572
|
}];
|
|
1545
1573
|
}
|
|
1546
1574
|
return [{
|
|
1547
|
-
id:
|
|
1575
|
+
id: AddDataValidationMutation.id,
|
|
1548
1576
|
params: {
|
|
1549
|
-
unitId
|
|
1550
|
-
subUnitId
|
|
1577
|
+
unitId,
|
|
1578
|
+
subUnitId,
|
|
1551
1579
|
rule: {
|
|
1552
|
-
...
|
|
1580
|
+
...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
|
|
1553
1581
|
},
|
|
1554
|
-
index:
|
|
1582
|
+
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
1555
1583
|
}
|
|
1556
1584
|
}];
|
|
1557
|
-
},
|
|
1558
|
-
type:
|
|
1585
|
+
}, "removeDataValidationUndoFactory"), RemoveSheetDataValidationCommand = {
|
|
1586
|
+
type: CommandType.COMMAND,
|
|
1559
1587
|
id: "sheet.command.remove-data-validation-rule",
|
|
1560
|
-
handler(
|
|
1561
|
-
if (!
|
|
1588
|
+
handler(accessor, params) {
|
|
1589
|
+
if (!params)
|
|
1562
1590
|
return !1;
|
|
1563
|
-
const { unitId
|
|
1564
|
-
id:
|
|
1565
|
-
params
|
|
1566
|
-
}],
|
|
1567
|
-
id:
|
|
1591
|
+
const { unitId, subUnitId, ruleId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), redoMutations = [{
|
|
1592
|
+
id: RemoveDataValidationMutation.id,
|
|
1593
|
+
params
|
|
1594
|
+
}], undoMutations = [{
|
|
1595
|
+
id: AddDataValidationMutation.id,
|
|
1568
1596
|
params: {
|
|
1569
|
-
unitId
|
|
1570
|
-
subUnitId
|
|
1597
|
+
unitId,
|
|
1598
|
+
subUnitId,
|
|
1571
1599
|
rule: {
|
|
1572
|
-
...
|
|
1600
|
+
...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
|
|
1573
1601
|
},
|
|
1574
|
-
index:
|
|
1602
|
+
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
1575
1603
|
}
|
|
1576
1604
|
}];
|
|
1577
|
-
return
|
|
1578
|
-
undoMutations
|
|
1579
|
-
redoMutations
|
|
1580
|
-
unitID:
|
|
1581
|
-
}),
|
|
1582
|
-
}
|
|
1583
|
-
},
|
|
1584
|
-
var
|
|
1585
|
-
for (var
|
|
1586
|
-
(
|
|
1587
|
-
return
|
|
1588
|
-
}, $
|
|
1589
|
-
let
|
|
1590
|
-
constructor(
|
|
1605
|
+
return undoRedoService.pushUndoRedo({
|
|
1606
|
+
undoMutations,
|
|
1607
|
+
redoMutations,
|
|
1608
|
+
unitID: params.unitId
|
|
1609
|
+
}), commandService.executeCommand(RemoveDataValidationMutation.id, params), !0;
|
|
1610
|
+
}
|
|
1611
|
+
}, SHEETS_DATA_VALIDATION_PLUGIN_CONFIG_KEY = "sheets-data-validation.config", defaultPluginConfig = {};
|
|
1612
|
+
var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1613
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1614
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1615
|
+
return kind && result && __defProp$6(target, key, result), result;
|
|
1616
|
+
}, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a5;
|
|
1617
|
+
let DataValidationFormulaRefRangeController = (_a5 = class extends Disposable {
|
|
1618
|
+
constructor(_dataValidationModel, _formulaRefRangeService, _validatorRegistryService) {
|
|
1591
1619
|
super();
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
});
|
|
1596
|
-
this._dataValidationModel =
|
|
1620
|
+
__publicField(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
1621
|
+
__publicField(this, "registerRule", /* @__PURE__ */ __name((unitId, subUnitId, rule) => {
|
|
1622
|
+
shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService) && this.register(unitId, subUnitId, rule);
|
|
1623
|
+
}, "registerRule"));
|
|
1624
|
+
this._dataValidationModel = _dataValidationModel, this._formulaRefRangeService = _formulaRefRangeService, this._validatorRegistryService = _validatorRegistryService, this._initRefRange();
|
|
1597
1625
|
}
|
|
1598
|
-
_getIdWithUnitId(
|
|
1599
|
-
return `${
|
|
1626
|
+
_getIdWithUnitId(unitID, subUnitId, ruleId) {
|
|
1627
|
+
return `${unitID}_${subUnitId}_${ruleId}`;
|
|
1600
1628
|
}
|
|
1601
1629
|
// eslint-disable-next-line max-lines-per-function
|
|
1602
|
-
register(
|
|
1603
|
-
const
|
|
1604
|
-
if (
|
|
1630
|
+
register(unitId, subUnitId, rule) {
|
|
1631
|
+
const oldRanges = rule.ranges, oldFormula1 = rule.formula1, oldFormula2 = rule.formula2, disposable = this._formulaRefRangeService.registerRangeFormula(unitId, subUnitId, oldRanges, [oldFormula1 != null ? oldFormula1 : "", oldFormula2 != null ? oldFormula2 : ""], (res) => {
|
|
1632
|
+
if (res.length === 0)
|
|
1605
1633
|
return {
|
|
1606
1634
|
undos: [{
|
|
1607
|
-
id:
|
|
1635
|
+
id: AddDataValidationMutation.id,
|
|
1608
1636
|
params: {
|
|
1609
|
-
unitId
|
|
1610
|
-
subUnitId
|
|
1611
|
-
rule
|
|
1637
|
+
unitId,
|
|
1638
|
+
subUnitId,
|
|
1639
|
+
rule,
|
|
1612
1640
|
source: "patched"
|
|
1613
1641
|
}
|
|
1614
1642
|
}],
|
|
1615
1643
|
redos: [{
|
|
1616
|
-
id:
|
|
1644
|
+
id: RemoveDataValidationMutation.id,
|
|
1617
1645
|
params: {
|
|
1618
|
-
unitId
|
|
1619
|
-
subUnitId
|
|
1620
|
-
ruleId:
|
|
1646
|
+
unitId,
|
|
1647
|
+
subUnitId,
|
|
1648
|
+
ruleId: rule.uid,
|
|
1621
1649
|
source: "patched"
|
|
1622
1650
|
}
|
|
1623
1651
|
}]
|
|
1624
1652
|
};
|
|
1625
|
-
const
|
|
1626
|
-
|
|
1627
|
-
id:
|
|
1653
|
+
const redos = [], undos = [], first = res[0];
|
|
1654
|
+
redos.push({
|
|
1655
|
+
id: UpdateDataValidationMutation.id,
|
|
1628
1656
|
params: {
|
|
1629
|
-
unitId
|
|
1630
|
-
subUnitId
|
|
1631
|
-
ruleId:
|
|
1657
|
+
unitId,
|
|
1658
|
+
subUnitId,
|
|
1659
|
+
ruleId: rule.uid,
|
|
1632
1660
|
payload: {
|
|
1633
|
-
type:
|
|
1661
|
+
type: UpdateRuleType.ALL,
|
|
1634
1662
|
payload: {
|
|
1635
|
-
ranges:
|
|
1636
|
-
formula1:
|
|
1637
|
-
formula2:
|
|
1663
|
+
ranges: first.ranges,
|
|
1664
|
+
formula1: first.formulas[0],
|
|
1665
|
+
formula2: first.formulas[1]
|
|
1638
1666
|
}
|
|
1639
1667
|
},
|
|
1640
1668
|
source: "patched"
|
|
1641
1669
|
}
|
|
1642
|
-
}),
|
|
1643
|
-
id:
|
|
1670
|
+
}), undos.push({
|
|
1671
|
+
id: UpdateDataValidationMutation.id,
|
|
1644
1672
|
params: {
|
|
1645
|
-
unitId
|
|
1646
|
-
subUnitId
|
|
1647
|
-
ruleId:
|
|
1673
|
+
unitId,
|
|
1674
|
+
subUnitId,
|
|
1675
|
+
ruleId: rule.uid,
|
|
1648
1676
|
payload: {
|
|
1649
|
-
type:
|
|
1677
|
+
type: UpdateRuleType.ALL,
|
|
1650
1678
|
payload: {
|
|
1651
|
-
ranges:
|
|
1652
|
-
formula1:
|
|
1653
|
-
formula2:
|
|
1679
|
+
ranges: oldRanges,
|
|
1680
|
+
formula1: oldFormula1,
|
|
1681
|
+
formula2: oldFormula2
|
|
1654
1682
|
}
|
|
1655
1683
|
},
|
|
1656
1684
|
source: "patched"
|
|
1657
1685
|
}
|
|
1658
1686
|
});
|
|
1659
|
-
for (let
|
|
1660
|
-
const
|
|
1661
|
-
|
|
1662
|
-
id:
|
|
1687
|
+
for (let i = 1; i < res.length; i++) {
|
|
1688
|
+
const item = res[i], id2 = generateRandomId();
|
|
1689
|
+
redos.push({
|
|
1690
|
+
id: AddDataValidationMutation.id,
|
|
1663
1691
|
params: {
|
|
1664
|
-
unitId
|
|
1665
|
-
subUnitId
|
|
1692
|
+
unitId,
|
|
1693
|
+
subUnitId,
|
|
1666
1694
|
rule: {
|
|
1667
|
-
...
|
|
1668
|
-
uid:
|
|
1669
|
-
formula1:
|
|
1670
|
-
formula2:
|
|
1671
|
-
ranges:
|
|
1695
|
+
...rule,
|
|
1696
|
+
uid: id2,
|
|
1697
|
+
formula1: item.formulas[0],
|
|
1698
|
+
formula2: item.formulas[1],
|
|
1699
|
+
ranges: item.ranges
|
|
1672
1700
|
},
|
|
1673
1701
|
source: "patched"
|
|
1674
1702
|
}
|
|
1675
|
-
}),
|
|
1676
|
-
id:
|
|
1703
|
+
}), undos.push({
|
|
1704
|
+
id: RemoveDataValidationMutation.id,
|
|
1677
1705
|
params: {
|
|
1678
|
-
unitId
|
|
1679
|
-
subUnitId
|
|
1680
|
-
ruleId:
|
|
1706
|
+
unitId,
|
|
1707
|
+
subUnitId,
|
|
1708
|
+
ruleId: id2,
|
|
1681
1709
|
source: "patched"
|
|
1682
1710
|
}
|
|
1683
1711
|
});
|
|
1684
1712
|
}
|
|
1685
1713
|
return {
|
|
1686
|
-
undos
|
|
1687
|
-
redos
|
|
1714
|
+
undos,
|
|
1715
|
+
redos
|
|
1688
1716
|
};
|
|
1689
|
-
}),
|
|
1690
|
-
this._disposableMap.set(
|
|
1717
|
+
}), id = this._getIdWithUnitId(unitId, subUnitId, rule.uid);
|
|
1718
|
+
this._disposableMap.set(id, disposable);
|
|
1691
1719
|
}
|
|
1692
1720
|
_initRefRange() {
|
|
1693
|
-
const
|
|
1694
|
-
for (const [
|
|
1695
|
-
for (const [
|
|
1696
|
-
for (const
|
|
1697
|
-
this.registerRule(
|
|
1721
|
+
const allRules = this._dataValidationModel.getAll();
|
|
1722
|
+
for (const [unitId, subUnitMap] of allRules)
|
|
1723
|
+
for (const [subUnitId, rules] of subUnitMap)
|
|
1724
|
+
for (const rule of rules)
|
|
1725
|
+
this.registerRule(unitId, subUnitId, rule);
|
|
1698
1726
|
this.disposeWithMe(
|
|
1699
|
-
this._dataValidationModel.ruleChange$.subscribe((
|
|
1700
|
-
const { unitId
|
|
1701
|
-
switch (
|
|
1727
|
+
this._dataValidationModel.ruleChange$.subscribe((option) => {
|
|
1728
|
+
const { unitId, subUnitId, rule } = option;
|
|
1729
|
+
switch (option.type) {
|
|
1702
1730
|
case "add": {
|
|
1703
|
-
const
|
|
1704
|
-
this.registerRule(
|
|
1731
|
+
const rule2 = option.rule;
|
|
1732
|
+
this.registerRule(option.unitId, option.subUnitId, rule2);
|
|
1705
1733
|
break;
|
|
1706
1734
|
}
|
|
1707
1735
|
case "remove": {
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1736
|
+
const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
|
|
1737
|
+
disposeSet && disposeSet.dispose();
|
|
1710
1738
|
break;
|
|
1711
1739
|
}
|
|
1712
1740
|
case "update": {
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1741
|
+
const rule2 = option.rule, disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule2.uid));
|
|
1742
|
+
disposeSet && disposeSet.dispose(), this.registerRule(option.unitId, option.subUnitId, rule2);
|
|
1715
1743
|
break;
|
|
1716
1744
|
}
|
|
1717
1745
|
}
|
|
1718
1746
|
})
|
|
1719
|
-
), this.disposeWithMe(
|
|
1720
|
-
this._disposableMap.forEach((
|
|
1721
|
-
|
|
1747
|
+
), this.disposeWithMe(toDisposable(() => {
|
|
1748
|
+
this._disposableMap.forEach((item) => {
|
|
1749
|
+
item.dispose();
|
|
1722
1750
|
}), this._disposableMap.clear();
|
|
1723
1751
|
}));
|
|
1724
1752
|
}
|
|
1725
|
-
};
|
|
1726
|
-
|
|
1727
|
-
$
|
|
1728
|
-
$
|
|
1729
|
-
$
|
|
1730
|
-
],
|
|
1731
|
-
var
|
|
1732
|
-
for (var
|
|
1733
|
-
(
|
|
1734
|
-
return
|
|
1735
|
-
},
|
|
1736
|
-
let
|
|
1737
|
-
constructor(
|
|
1738
|
-
super(), this._univerInstanceService =
|
|
1739
|
-
}
|
|
1740
|
-
getFormulaRefCheck(
|
|
1741
|
-
var
|
|
1742
|
-
const
|
|
1743
|
-
if (!
|
|
1753
|
+
}, __name(_a5, "DataValidationFormulaRefRangeController"), _a5);
|
|
1754
|
+
DataValidationFormulaRefRangeController = __decorateClass$6([
|
|
1755
|
+
__decorateParam$6(0, Inject(SheetDataValidationModel)),
|
|
1756
|
+
__decorateParam$6(1, Inject(FormulaRefRangeService)),
|
|
1757
|
+
__decorateParam$6(2, Inject(DataValidatorRegistryService))
|
|
1758
|
+
], DataValidationFormulaRefRangeController);
|
|
1759
|
+
var R = /* @__PURE__ */ ((E) => (E[E.View = 0] = "View", E[E.Edit = 1] = "Edit", E[E.ManageCollaborator = 2] = "ManageCollaborator", E[E.Print = 3] = "Print", E[E.Duplicate = 4] = "Duplicate", E[E.Comment = 5] = "Comment", E[E.Copy = 6] = "Copy", E[E.Share = 7] = "Share", E[E.Export = 8] = "Export", E[E.MoveWorksheet = 9] = "MoveWorksheet", E[E.DeleteWorksheet = 10] = "DeleteWorksheet", E[E.HideWorksheet = 11] = "HideWorksheet", E[E.RenameWorksheet = 12] = "RenameWorksheet", E[E.CreateWorksheet = 13] = "CreateWorksheet", E[E.SetWorksheetStyle = 14] = "SetWorksheetStyle", E[E.EditWorksheetCell = 15] = "EditWorksheetCell", E[E.InsertHyperlink = 16] = "InsertHyperlink", E[E.Sort = 17] = "Sort", E[E.Filter = 18] = "Filter", E[E.PivotTable = 19] = "PivotTable", E[E.FloatImg = 20] = "FloatImg", E[E.History = 21] = "History", E[E.RwHgtClWdt = 22] = "RwHgtClWdt", E[E.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", E[E.ViewFilter = 24] = "ViewFilter", E[E.MoveSheet = 25] = "MoveSheet", E[E.DeleteSheet = 26] = "DeleteSheet", E[E.HideSheet = 27] = "HideSheet", E[E.CopySheet = 28] = "CopySheet", E[E.RenameSheet = 29] = "RenameSheet", E[E.CreateSheet = 30] = "CreateSheet", E[E.SelectProtectedCells = 31] = "SelectProtectedCells", E[E.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", E[E.SetCellStyle = 33] = "SetCellStyle", E[E.SetCellValue = 34] = "SetCellValue", E[E.SetRowStyle = 35] = "SetRowStyle", E[E.SetColumnStyle = 36] = "SetColumnStyle", E[E.InsertRow = 37] = "InsertRow", E[E.InsertColumn = 38] = "InsertColumn", E[E.DeleteRow = 39] = "DeleteRow", E[E.DeleteColumn = 40] = "DeleteColumn", E[E.EditExtraObject = 41] = "EditExtraObject", E[E.Delete = 42] = "Delete", E[E.RecoverHistory = 43] = "RecoverHistory", E[E.ViewHistory = 44] = "ViewHistory", E[E.CreatePermissionObject = 45] = "CreatePermissionObject", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(R || {}), __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1760
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1761
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1762
|
+
return kind && result && __defProp$5(target, key, result), result;
|
|
1763
|
+
}, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a6;
|
|
1764
|
+
let DataValidationFormulaController = (_a6 = class extends Disposable {
|
|
1765
|
+
constructor(_univerInstanceService, _permissionService, _lexerTreeBuilder) {
|
|
1766
|
+
super(), this._univerInstanceService = _univerInstanceService, this._permissionService = _permissionService, this._lexerTreeBuilder = _lexerTreeBuilder;
|
|
1767
|
+
}
|
|
1768
|
+
getFormulaRefCheck(formulaString) {
|
|
1769
|
+
var _a12, _b;
|
|
1770
|
+
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
|
|
1771
|
+
if (!sequenceNodes)
|
|
1744
1772
|
return !0;
|
|
1745
|
-
for (let
|
|
1746
|
-
const
|
|
1747
|
-
if (typeof
|
|
1773
|
+
for (let i = 0; i < sequenceNodes.length; i++) {
|
|
1774
|
+
const node = sequenceNodes[i];
|
|
1775
|
+
if (typeof node == "string")
|
|
1748
1776
|
continue;
|
|
1749
|
-
const { token
|
|
1750
|
-
let
|
|
1751
|
-
const
|
|
1752
|
-
if (
|
|
1753
|
-
if (
|
|
1777
|
+
const { token } = node, sequenceGrid = deserializeRangeWithSheetWithCache(token), workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
1778
|
+
let targetSheet = workbook.getActiveSheet();
|
|
1779
|
+
const unitId = workbook.getUnitId();
|
|
1780
|
+
if (sequenceGrid.sheetName) {
|
|
1781
|
+
if (targetSheet = workbook.getSheetBySheetName(sequenceGrid.sheetName), !targetSheet)
|
|
1754
1782
|
return !1;
|
|
1755
|
-
const
|
|
1756
|
-
if (!this._permissionService.getPermissionPoint(new
|
|
1783
|
+
const subUnitId = targetSheet == null ? void 0 : targetSheet.getSheetId();
|
|
1784
|
+
if (!this._permissionService.getPermissionPoint(new WorksheetViewPermission(unitId, subUnitId).id)) return !1;
|
|
1757
1785
|
}
|
|
1758
|
-
if (!
|
|
1786
|
+
if (!targetSheet)
|
|
1759
1787
|
return !1;
|
|
1760
|
-
const { startRow
|
|
1761
|
-
for (let
|
|
1762
|
-
for (let
|
|
1763
|
-
const
|
|
1764
|
-
if ((
|
|
1788
|
+
const { startRow, endRow, startColumn, endColumn } = sequenceGrid.range;
|
|
1789
|
+
for (let i2 = startRow; i2 <= endRow; i2++)
|
|
1790
|
+
for (let j = startColumn; j <= endColumn; j++) {
|
|
1791
|
+
const permission = (_b = (_a12 = targetSheet.getCell(i2, j)) == null ? void 0 : _a12.selectionProtection) == null ? void 0 : _b[0];
|
|
1792
|
+
if ((permission == null ? void 0 : permission[R.View]) === !1)
|
|
1765
1793
|
return !1;
|
|
1766
1794
|
}
|
|
1767
1795
|
}
|
|
1768
1796
|
return !0;
|
|
1769
1797
|
}
|
|
1770
|
-
};
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
],
|
|
1776
|
-
var
|
|
1777
|
-
for (var
|
|
1778
|
-
(
|
|
1779
|
-
return
|
|
1780
|
-
},
|
|
1781
|
-
let
|
|
1782
|
-
constructor(
|
|
1798
|
+
}, __name(_a6, "DataValidationFormulaController"), _a6);
|
|
1799
|
+
DataValidationFormulaController = __decorateClass$5([
|
|
1800
|
+
__decorateParam$5(0, IUniverInstanceService),
|
|
1801
|
+
__decorateParam$5(1, IPermissionService),
|
|
1802
|
+
__decorateParam$5(2, Inject(LexerTreeBuilder))
|
|
1803
|
+
], DataValidationFormulaController);
|
|
1804
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1805
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1806
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1807
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
1808
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a7;
|
|
1809
|
+
let DataValidationRefRangeController = (_a7 = class extends Disposable {
|
|
1810
|
+
constructor(_dataValidationModel, _injector, _refRangeService, _dataValidationFormulaService, _formulaRefRangeService, _validatorRegistryService) {
|
|
1783
1811
|
super();
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
});
|
|
1788
|
-
this._dataValidationModel =
|
|
1812
|
+
__publicField(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
1813
|
+
__publicField(this, "registerRule", /* @__PURE__ */ __name((unitId, subUnitId, rule) => {
|
|
1814
|
+
shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService) || (this.register(unitId, subUnitId, rule), this.registerFormula(unitId, subUnitId, rule));
|
|
1815
|
+
}, "registerRule"));
|
|
1816
|
+
this._dataValidationModel = _dataValidationModel, this._injector = _injector, this._refRangeService = _refRangeService, this._dataValidationFormulaService = _dataValidationFormulaService, this._formulaRefRangeService = _formulaRefRangeService, this._validatorRegistryService = _validatorRegistryService, this._initRefRange();
|
|
1789
1817
|
}
|
|
1790
|
-
_getIdWithUnitId(
|
|
1791
|
-
return `${
|
|
1818
|
+
_getIdWithUnitId(unitID, subUnitId, ruleId) {
|
|
1819
|
+
return `${unitID}_${subUnitId}_${ruleId}`;
|
|
1792
1820
|
}
|
|
1793
1821
|
// eslint-disable-next-line max-lines-per-function
|
|
1794
|
-
registerFormula(
|
|
1795
|
-
var
|
|
1796
|
-
const
|
|
1797
|
-
const
|
|
1798
|
-
if (!
|
|
1822
|
+
registerFormula(unitId, subUnitId, rule) {
|
|
1823
|
+
var _a12;
|
|
1824
|
+
const ruleId = rule.uid, id = this._getIdWithUnitId(unitId, subUnitId, ruleId), disposeSet = (_a12 = this._disposableMap.get(id)) != null ? _a12 : /* @__PURE__ */ new Set(), handleFormulaChange = /* @__PURE__ */ __name((type, formulaString) => {
|
|
1825
|
+
const oldRule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1826
|
+
if (!oldRule)
|
|
1799
1827
|
return { redos: [], undos: [] };
|
|
1800
|
-
const
|
|
1801
|
-
if (!
|
|
1828
|
+
const oldFormula = oldRule[type];
|
|
1829
|
+
if (!oldFormula || oldFormula === formulaString)
|
|
1802
1830
|
return { redos: [], undos: [] };
|
|
1803
|
-
const
|
|
1804
|
-
unitId
|
|
1805
|
-
subUnitId
|
|
1806
|
-
ruleId:
|
|
1831
|
+
const redoParams = {
|
|
1832
|
+
unitId,
|
|
1833
|
+
subUnitId,
|
|
1834
|
+
ruleId: rule.uid,
|
|
1807
1835
|
payload: {
|
|
1808
|
-
type:
|
|
1836
|
+
type: UpdateRuleType.SETTING,
|
|
1809
1837
|
payload: {
|
|
1810
|
-
type:
|
|
1811
|
-
formula1:
|
|
1812
|
-
formula2:
|
|
1813
|
-
[
|
|
1838
|
+
type: oldRule.type,
|
|
1839
|
+
formula1: oldRule.formula1,
|
|
1840
|
+
formula2: oldRule.formula2,
|
|
1841
|
+
[type]: formulaString
|
|
1814
1842
|
}
|
|
1815
1843
|
},
|
|
1816
1844
|
source: "patched"
|
|
1817
|
-
},
|
|
1818
|
-
unitId
|
|
1819
|
-
subUnitId
|
|
1820
|
-
ruleId:
|
|
1845
|
+
}, undoParams = {
|
|
1846
|
+
unitId,
|
|
1847
|
+
subUnitId,
|
|
1848
|
+
ruleId: rule.uid,
|
|
1821
1849
|
payload: {
|
|
1822
|
-
type:
|
|
1850
|
+
type: UpdateRuleType.SETTING,
|
|
1823
1851
|
payload: {
|
|
1824
|
-
type:
|
|
1825
|
-
formula1:
|
|
1826
|
-
formula2:
|
|
1852
|
+
type: oldRule.type,
|
|
1853
|
+
formula1: oldRule.formula1,
|
|
1854
|
+
formula2: oldRule.formula2
|
|
1827
1855
|
}
|
|
1828
1856
|
},
|
|
1829
1857
|
source: "patched"
|
|
1830
|
-
},
|
|
1858
|
+
}, redos = [
|
|
1831
1859
|
{
|
|
1832
|
-
id:
|
|
1833
|
-
params:
|
|
1860
|
+
id: UpdateDataValidationMutation.id,
|
|
1861
|
+
params: redoParams
|
|
1834
1862
|
}
|
|
1835
|
-
],
|
|
1863
|
+
], undos = [
|
|
1836
1864
|
{
|
|
1837
|
-
id:
|
|
1838
|
-
params:
|
|
1865
|
+
id: UpdateDataValidationMutation.id,
|
|
1866
|
+
params: undoParams
|
|
1839
1867
|
}
|
|
1840
1868
|
];
|
|
1841
|
-
return { redos
|
|
1842
|
-
},
|
|
1843
|
-
if (
|
|
1844
|
-
const [
|
|
1845
|
-
if (
|
|
1846
|
-
const
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
(
|
|
1869
|
+
return { redos, undos };
|
|
1870
|
+
}, "handleFormulaChange"), currentFormula = this._dataValidationFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
|
|
1871
|
+
if (currentFormula) {
|
|
1872
|
+
const [formula1, formula2] = currentFormula;
|
|
1873
|
+
if (formula1) {
|
|
1874
|
+
const disposable = this._formulaRefRangeService.registerFormula(
|
|
1875
|
+
unitId,
|
|
1876
|
+
subUnitId,
|
|
1877
|
+
formula1.text,
|
|
1878
|
+
(newFormulaString) => handleFormulaChange("formula1", newFormulaString)
|
|
1851
1879
|
);
|
|
1852
|
-
|
|
1880
|
+
disposeSet.add(() => disposable.dispose());
|
|
1853
1881
|
}
|
|
1854
|
-
if (
|
|
1855
|
-
const
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
(
|
|
1882
|
+
if (formula2) {
|
|
1883
|
+
const disposable = this._formulaRefRangeService.registerFormula(
|
|
1884
|
+
unitId,
|
|
1885
|
+
subUnitId,
|
|
1886
|
+
formula2.text,
|
|
1887
|
+
(newFormulaString) => handleFormulaChange("formula2", newFormulaString)
|
|
1860
1888
|
);
|
|
1861
|
-
|
|
1889
|
+
disposeSet.add(() => disposable.dispose());
|
|
1862
1890
|
}
|
|
1863
1891
|
}
|
|
1864
1892
|
}
|
|
1865
|
-
register(
|
|
1866
|
-
var
|
|
1867
|
-
const
|
|
1868
|
-
const
|
|
1869
|
-
if (
|
|
1893
|
+
register(unitId, subUnitId, rule) {
|
|
1894
|
+
var _a12;
|
|
1895
|
+
const handleRangeChange = /* @__PURE__ */ __name((commandInfo) => {
|
|
1896
|
+
const oldRanges = [...rule.ranges], resultRanges = oldRanges.map((range) => handleCommonDefaultRangeChangeWithEffectRefCommands(range, commandInfo)).filter((range) => !!range).flat();
|
|
1897
|
+
if (isRangesEqual(resultRanges, oldRanges))
|
|
1870
1898
|
return { redos: [], undos: [] };
|
|
1871
|
-
if (
|
|
1872
|
-
const
|
|
1873
|
-
unitId
|
|
1874
|
-
subUnitId
|
|
1875
|
-
ruleId:
|
|
1899
|
+
if (resultRanges.length) {
|
|
1900
|
+
const redoParams = {
|
|
1901
|
+
unitId,
|
|
1902
|
+
subUnitId,
|
|
1903
|
+
ruleId: rule.uid,
|
|
1876
1904
|
payload: {
|
|
1877
|
-
type:
|
|
1878
|
-
payload:
|
|
1905
|
+
type: UpdateRuleType.RANGE,
|
|
1906
|
+
payload: resultRanges
|
|
1879
1907
|
},
|
|
1880
1908
|
source: "patched"
|
|
1881
|
-
},
|
|
1882
|
-
id:
|
|
1909
|
+
}, redos = [{ id: UpdateDataValidationMutation.id, params: redoParams }], undos = [{
|
|
1910
|
+
id: UpdateDataValidationMutation.id,
|
|
1883
1911
|
params: {
|
|
1884
|
-
unitId
|
|
1885
|
-
subUnitId
|
|
1886
|
-
ruleId:
|
|
1912
|
+
unitId,
|
|
1913
|
+
subUnitId,
|
|
1914
|
+
ruleId: rule.uid,
|
|
1887
1915
|
payload: {
|
|
1888
|
-
type:
|
|
1889
|
-
payload:
|
|
1916
|
+
type: UpdateRuleType.RANGE,
|
|
1917
|
+
payload: oldRanges
|
|
1890
1918
|
},
|
|
1891
1919
|
source: "patched"
|
|
1892
1920
|
}
|
|
1893
1921
|
}];
|
|
1894
|
-
return { redos
|
|
1922
|
+
return { redos, undos };
|
|
1895
1923
|
} else {
|
|
1896
|
-
const
|
|
1897
|
-
return { redos
|
|
1924
|
+
const redoParams = { unitId, subUnitId, ruleId: rule.uid }, redos = [{ id: RemoveDataValidationMutation.id, params: redoParams }], undos = removeDataValidationUndoFactory(this._injector, redoParams);
|
|
1925
|
+
return { redos, undos };
|
|
1898
1926
|
}
|
|
1899
|
-
},
|
|
1900
|
-
|
|
1901
|
-
const
|
|
1902
|
-
|
|
1927
|
+
}, "handleRangeChange"), disposeList = [];
|
|
1928
|
+
rule.ranges.forEach((range) => {
|
|
1929
|
+
const disposable = this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId);
|
|
1930
|
+
disposeList.push(() => disposable.dispose());
|
|
1903
1931
|
});
|
|
1904
|
-
const
|
|
1905
|
-
|
|
1932
|
+
const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid), current = (_a12 = this._disposableMap.get(id)) != null ? _a12 : /* @__PURE__ */ new Set();
|
|
1933
|
+
current.add(() => disposeList.forEach((dispose) => dispose())), this._disposableMap.set(id, current);
|
|
1906
1934
|
}
|
|
1907
1935
|
_initRefRange() {
|
|
1908
|
-
const
|
|
1909
|
-
for (const [
|
|
1910
|
-
for (const [
|
|
1911
|
-
for (const
|
|
1912
|
-
this.registerRule(
|
|
1936
|
+
const allRules = this._dataValidationModel.getAll();
|
|
1937
|
+
for (const [unitId, subUnitMap] of allRules)
|
|
1938
|
+
for (const [subUnitId, rules] of subUnitMap)
|
|
1939
|
+
for (const rule of rules)
|
|
1940
|
+
this.registerRule(unitId, subUnitId, rule);
|
|
1913
1941
|
this.disposeWithMe(
|
|
1914
|
-
this._dataValidationModel.ruleChange$.subscribe((
|
|
1915
|
-
const { unitId
|
|
1916
|
-
switch (
|
|
1942
|
+
this._dataValidationModel.ruleChange$.subscribe((option) => {
|
|
1943
|
+
const { unitId, subUnitId, rule } = option;
|
|
1944
|
+
switch (option.type) {
|
|
1917
1945
|
case "add": {
|
|
1918
|
-
const
|
|
1919
|
-
this.registerRule(
|
|
1946
|
+
const rule2 = option.rule;
|
|
1947
|
+
this.registerRule(option.unitId, option.subUnitId, rule2);
|
|
1920
1948
|
break;
|
|
1921
1949
|
}
|
|
1922
1950
|
case "remove": {
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1951
|
+
const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
|
|
1952
|
+
disposeSet && disposeSet.forEach((dispose) => dispose());
|
|
1925
1953
|
break;
|
|
1926
1954
|
}
|
|
1927
1955
|
case "update": {
|
|
1928
|
-
const
|
|
1929
|
-
|
|
1956
|
+
const rule2 = option.rule, disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule2.uid));
|
|
1957
|
+
disposeSet && disposeSet.forEach((dispose) => dispose()), this.registerRule(option.unitId, option.subUnitId, rule2);
|
|
1930
1958
|
break;
|
|
1931
1959
|
}
|
|
1932
1960
|
}
|
|
1933
1961
|
})
|
|
1934
|
-
), this.disposeWithMe(
|
|
1935
|
-
this._disposableMap.forEach((
|
|
1936
|
-
|
|
1962
|
+
), this.disposeWithMe(toDisposable(() => {
|
|
1963
|
+
this._disposableMap.forEach((item) => {
|
|
1964
|
+
item.forEach((dispose) => dispose());
|
|
1937
1965
|
}), this._disposableMap.clear();
|
|
1938
1966
|
}));
|
|
1939
1967
|
}
|
|
1940
|
-
};
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
],
|
|
1949
|
-
var
|
|
1950
|
-
for (var
|
|
1951
|
-
(
|
|
1952
|
-
return
|
|
1953
|
-
},
|
|
1954
|
-
let
|
|
1955
|
-
constructor(
|
|
1956
|
-
super(), this._sheetInterceptorService =
|
|
1968
|
+
}, __name(_a7, "DataValidationRefRangeController"), _a7);
|
|
1969
|
+
DataValidationRefRangeController = __decorateClass$4([
|
|
1970
|
+
__decorateParam$4(0, Inject(SheetDataValidationModel)),
|
|
1971
|
+
__decorateParam$4(1, Inject(Injector)),
|
|
1972
|
+
__decorateParam$4(2, Inject(RefRangeService)),
|
|
1973
|
+
__decorateParam$4(3, Inject(DataValidationFormulaService)),
|
|
1974
|
+
__decorateParam$4(4, Inject(FormulaRefRangeService)),
|
|
1975
|
+
__decorateParam$4(5, Inject(DataValidatorRegistryService))
|
|
1976
|
+
], DataValidationRefRangeController);
|
|
1977
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1978
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1979
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1980
|
+
return kind && result && __defProp$3(target, key, result), result;
|
|
1981
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a8;
|
|
1982
|
+
let SheetDataValidationSheetController = (_a8 = class extends Disposable {
|
|
1983
|
+
constructor(_sheetInterceptorService, _univerInstanceService, _sheetDataValidationModel) {
|
|
1984
|
+
super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._sheetDataValidationModel = _sheetDataValidationModel, this._initSheetChange();
|
|
1957
1985
|
}
|
|
1958
1986
|
_initSheetChange() {
|
|
1959
1987
|
this.disposeWithMe(
|
|
1960
1988
|
this._sheetInterceptorService.interceptCommand({
|
|
1961
|
-
getMutations: (
|
|
1962
|
-
var
|
|
1963
|
-
if (
|
|
1964
|
-
const
|
|
1965
|
-
if (!
|
|
1989
|
+
getMutations: /* @__PURE__ */ __name((commandInfo) => {
|
|
1990
|
+
var _a12;
|
|
1991
|
+
if (commandInfo.id === RemoveSheetCommand.id) {
|
|
1992
|
+
const params = commandInfo.params, unitId = params.unitId || this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId(), workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
|
|
1993
|
+
if (!workbook)
|
|
1966
1994
|
return { redos: [], undos: [] };
|
|
1967
|
-
const
|
|
1968
|
-
if (!
|
|
1995
|
+
const subUnitId = params.subUnitId || ((_a12 = workbook.getActiveSheet()) == null ? void 0 : _a12.getSheetId());
|
|
1996
|
+
if (!subUnitId)
|
|
1969
1997
|
return { redos: [], undos: [] };
|
|
1970
|
-
const
|
|
1971
|
-
if (
|
|
1998
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
1999
|
+
if (rules.length === 0)
|
|
1972
2000
|
return { redos: [], undos: [] };
|
|
1973
|
-
const
|
|
1974
|
-
unitId
|
|
1975
|
-
subUnitId
|
|
1976
|
-
ruleId:
|
|
2001
|
+
const ids = rules.map((i) => i.uid), redoParams = {
|
|
2002
|
+
unitId,
|
|
2003
|
+
subUnitId,
|
|
2004
|
+
ruleId: ids,
|
|
1977
2005
|
source: "patched"
|
|
1978
|
-
},
|
|
1979
|
-
unitId
|
|
1980
|
-
subUnitId
|
|
1981
|
-
rule: [...
|
|
2006
|
+
}, undoParams = {
|
|
2007
|
+
unitId,
|
|
2008
|
+
subUnitId,
|
|
2009
|
+
rule: [...rules],
|
|
1982
2010
|
source: "patched"
|
|
1983
2011
|
};
|
|
1984
2012
|
return {
|
|
1985
2013
|
redos: [{
|
|
1986
|
-
id:
|
|
1987
|
-
params:
|
|
2014
|
+
id: RemoveDataValidationMutation.id,
|
|
2015
|
+
params: redoParams
|
|
1988
2016
|
}],
|
|
1989
2017
|
undos: [{
|
|
1990
|
-
id:
|
|
1991
|
-
params:
|
|
2018
|
+
id: AddDataValidationMutation.id,
|
|
2019
|
+
params: undoParams
|
|
1992
2020
|
}]
|
|
1993
2021
|
};
|
|
1994
2022
|
}
|
|
1995
2023
|
return { redos: [], undos: [] };
|
|
1996
|
-
}
|
|
2024
|
+
}, "getMutations")
|
|
1997
2025
|
})
|
|
1998
2026
|
);
|
|
1999
2027
|
}
|
|
2000
|
-
};
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
],
|
|
2006
|
-
class
|
|
2028
|
+
}, __name(_a8, "SheetDataValidationSheetController"), _a8);
|
|
2029
|
+
SheetDataValidationSheetController = __decorateClass$3([
|
|
2030
|
+
__decorateParam$3(0, Inject(SheetInterceptorService)),
|
|
2031
|
+
__decorateParam$3(1, Inject(IUniverInstanceService)),
|
|
2032
|
+
__decorateParam$3(2, Inject(SheetDataValidationModel))
|
|
2033
|
+
], SheetDataValidationSheetController);
|
|
2034
|
+
const _AnyValidator = class _AnyValidator extends BaseDataValidator {
|
|
2007
2035
|
constructor() {
|
|
2008
2036
|
super(...arguments);
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2037
|
+
__publicField(this, "id", DataValidationType.ANY);
|
|
2038
|
+
__publicField(this, "title", "dataValidation.any.title");
|
|
2039
|
+
__publicField(this, "operators", []);
|
|
2040
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
2041
|
+
__publicField(this, "offsetFormulaByRange", !1);
|
|
2014
2042
|
}
|
|
2015
|
-
async parseFormula(
|
|
2043
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
2016
2044
|
return {
|
|
2017
|
-
formula1:
|
|
2018
|
-
formula2:
|
|
2045
|
+
formula1: rule.formula1,
|
|
2046
|
+
formula2: rule.formula2,
|
|
2019
2047
|
isFormulaValid: !0
|
|
2020
2048
|
};
|
|
2021
2049
|
}
|
|
2022
|
-
validatorFormula(
|
|
2050
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
2023
2051
|
return {
|
|
2024
2052
|
success: !0
|
|
2025
2053
|
};
|
|
2026
2054
|
}
|
|
2027
|
-
async isValidType(
|
|
2055
|
+
async isValidType(cellInfo, formula, rule) {
|
|
2028
2056
|
return !0;
|
|
2029
2057
|
}
|
|
2030
|
-
generateRuleErrorMessage(
|
|
2058
|
+
generateRuleErrorMessage(rule) {
|
|
2031
2059
|
return this.localeService.t("dataValidation.any.error");
|
|
2032
2060
|
}
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2061
|
+
};
|
|
2062
|
+
__name(_AnyValidator, "AnyValidator");
|
|
2063
|
+
let AnyValidator = _AnyValidator;
|
|
2064
|
+
const _CustomFormulaValidator = class _CustomFormulaValidator extends BaseDataValidator {
|
|
2035
2065
|
constructor() {
|
|
2036
2066
|
super(...arguments);
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2067
|
+
__publicField(this, "id", DataValidationType.CUSTOM);
|
|
2068
|
+
__publicField(this, "title", "dataValidation.custom.title");
|
|
2069
|
+
__publicField(this, "operators", []);
|
|
2070
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
2071
|
+
__publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
2072
|
+
__publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
|
|
2073
|
+
}
|
|
2074
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
2075
|
+
var _a12;
|
|
2076
|
+
const success = isFormulaString(rule.formula1), formulaText = (_a12 = rule.formula1) != null ? _a12 : "", valid = this._lexerTreeBuilder.checkIfAddBracket(formulaText) === 0 && formulaText.startsWith(operatorToken.EQUALS);
|
|
2045
2077
|
return {
|
|
2046
|
-
success:
|
|
2047
|
-
formula1:
|
|
2078
|
+
success: success && valid,
|
|
2079
|
+
formula1: success && valid ? "" : this.localeService.t("dataValidation.validFail.formula")
|
|
2048
2080
|
};
|
|
2049
2081
|
}
|
|
2050
|
-
async parseFormula(
|
|
2082
|
+
async parseFormula(_rule, _unitId, _subUnitId) {
|
|
2051
2083
|
return {
|
|
2052
2084
|
formula1: void 0,
|
|
2053
2085
|
formula2: void 0,
|
|
2054
2086
|
isFormulaValid: !0
|
|
2055
2087
|
};
|
|
2056
2088
|
}
|
|
2057
|
-
async isValidType(
|
|
2058
|
-
const { column
|
|
2059
|
-
return
|
|
2089
|
+
async isValidType(cellInfo, _formula, _rule) {
|
|
2090
|
+
const { column, row, unitId, subUnitId } = cellInfo, cellData = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, _rule.uid, row, column), formulaResult = cellData == null ? void 0 : cellData.v;
|
|
2091
|
+
return isLegalFormulaResult(String(formulaResult)) && Tools.isDefine(formulaResult) && formulaResult !== "" ? cellData.t === CellValueType.BOOLEAN ? !!formulaResult : typeof formulaResult == "boolean" ? formulaResult : typeof formulaResult == "number" ? !!formulaResult : typeof formulaResult == "string" ? isLegalFormulaResult(formulaResult) : !!formulaResult : !1;
|
|
2060
2092
|
}
|
|
2061
|
-
generateRuleErrorMessage(
|
|
2093
|
+
generateRuleErrorMessage(rule) {
|
|
2062
2094
|
return this.localeService.t("dataValidation.custom.error");
|
|
2063
2095
|
}
|
|
2064
|
-
generateRuleName(
|
|
2065
|
-
var
|
|
2066
|
-
return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (
|
|
2096
|
+
generateRuleName(rule) {
|
|
2097
|
+
var _a12;
|
|
2098
|
+
return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (_a12 = rule.formula1) != null ? _a12 : "");
|
|
2067
2099
|
}
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2100
|
+
};
|
|
2101
|
+
__name(_CustomFormulaValidator, "CustomFormulaValidator");
|
|
2102
|
+
let CustomFormulaValidator = _CustomFormulaValidator;
|
|
2103
|
+
const _ListMultipleValidator = class _ListMultipleValidator extends ListValidator {
|
|
2070
2104
|
constructor() {
|
|
2071
2105
|
super(...arguments);
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2106
|
+
__publicField(this, "id", DataValidationType.LIST_MULTIPLE);
|
|
2107
|
+
__publicField(this, "title", "dataValidation.listMultiple.title");
|
|
2108
|
+
__publicField(this, "offsetFormulaByRange", !1);
|
|
2109
|
+
__publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name(() => !0, "skipDefaultFontRender"));
|
|
2076
2110
|
}
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2111
|
+
};
|
|
2112
|
+
__name(_ListMultipleValidator, "ListMultipleValidator");
|
|
2113
|
+
let ListMultipleValidator = _ListMultipleValidator;
|
|
2114
|
+
const _WholeValidator = class _WholeValidator extends BaseDataValidator {
|
|
2079
2115
|
constructor() {
|
|
2080
2116
|
super(...arguments);
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2117
|
+
__publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
|
|
2118
|
+
__publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
|
|
2119
|
+
__publicField(this, "id", DataValidationType.WHOLE);
|
|
2120
|
+
__publicField(this, "title", "dataValidation.whole.title");
|
|
2121
|
+
__publicField(this, "operators", [
|
|
2122
|
+
DataValidationOperator.BETWEEN,
|
|
2123
|
+
DataValidationOperator.EQUAL,
|
|
2124
|
+
DataValidationOperator.GREATER_THAN,
|
|
2125
|
+
DataValidationOperator.GREATER_THAN_OR_EQUAL,
|
|
2126
|
+
DataValidationOperator.LESS_THAN,
|
|
2127
|
+
DataValidationOperator.LESS_THAN_OR_EQUAL,
|
|
2128
|
+
DataValidationOperator.NOT_BETWEEN,
|
|
2129
|
+
DataValidationOperator.NOT_EQUAL
|
|
2094
2130
|
]);
|
|
2095
|
-
|
|
2131
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
2096
2132
|
}
|
|
2097
|
-
_isFormulaOrInt(
|
|
2098
|
-
return !
|
|
2133
|
+
_isFormulaOrInt(formula) {
|
|
2134
|
+
return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula) && Number.isInteger(+formula));
|
|
2099
2135
|
}
|
|
2100
|
-
async isValidType(
|
|
2101
|
-
const { value:
|
|
2102
|
-
return !Number.isNaN(
|
|
2136
|
+
async isValidType(cellInfo, _formula, _rule) {
|
|
2137
|
+
const { value: cellValue } = cellInfo, num = getCellValueNumber(cellValue);
|
|
2138
|
+
return !Number.isNaN(num) && Number.isInteger(num);
|
|
2103
2139
|
}
|
|
2104
|
-
transform(
|
|
2105
|
-
const { value:
|
|
2140
|
+
transform(cellInfo, _formula, _rule) {
|
|
2141
|
+
const { value: cellValue } = cellInfo;
|
|
2106
2142
|
return {
|
|
2107
|
-
...
|
|
2108
|
-
value:
|
|
2143
|
+
...cellInfo,
|
|
2144
|
+
value: getCellValueNumber(cellValue)
|
|
2109
2145
|
};
|
|
2110
2146
|
}
|
|
2111
|
-
_parseNumber(
|
|
2112
|
-
return
|
|
2147
|
+
_parseNumber(formula) {
|
|
2148
|
+
return formula == null ? Number.NaN : +formula;
|
|
2113
2149
|
}
|
|
2114
|
-
async parseFormula(
|
|
2115
|
-
const
|
|
2150
|
+
async parseFormula(rule, unitId, subUnitId, row, column) {
|
|
2151
|
+
const res1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), res2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, formula1Result = isFormulaString(formula1) ? res1 == null ? void 0 : res1.v : formula1, formula2Result = isFormulaString(formula2) ? res2 == null ? void 0 : res2.v : formula2, isFormulaValid = isLegalFormulaResult(`${formula1Result}`) && isLegalFormulaResult(`${formula2Result}`);
|
|
2116
2152
|
return {
|
|
2117
|
-
formula1: this._parseNumber(
|
|
2118
|
-
formula2: this._parseNumber(
|
|
2119
|
-
isFormulaValid
|
|
2153
|
+
formula1: this._parseNumber(formula1Result),
|
|
2154
|
+
formula2: this._parseNumber(formula2Result),
|
|
2155
|
+
isFormulaValid
|
|
2120
2156
|
};
|
|
2121
2157
|
}
|
|
2122
|
-
validatorFormula(
|
|
2123
|
-
const
|
|
2124
|
-
if (!
|
|
2158
|
+
validatorFormula(rule, _unitId, _subUnitId) {
|
|
2159
|
+
const operator = rule.operator;
|
|
2160
|
+
if (!operator)
|
|
2125
2161
|
return {
|
|
2126
2162
|
success: !1
|
|
2127
2163
|
};
|
|
2128
|
-
const
|
|
2129
|
-
return
|
|
2130
|
-
success:
|
|
2131
|
-
formula1:
|
|
2132
|
-
formula2:
|
|
2164
|
+
const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1), formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2), isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator), errorMsg = this.localeService.t("dataValidation.validFail.number");
|
|
2165
|
+
return isTwoFormula ? {
|
|
2166
|
+
success: formula1Success && formula2Success,
|
|
2167
|
+
formula1: formula1Success ? void 0 : errorMsg,
|
|
2168
|
+
formula2: formula2Success ? void 0 : errorMsg
|
|
2133
2169
|
} : {
|
|
2134
|
-
success:
|
|
2135
|
-
formula1:
|
|
2170
|
+
success: formula1Success,
|
|
2171
|
+
formula1: errorMsg
|
|
2136
2172
|
};
|
|
2137
2173
|
}
|
|
2138
|
-
generateRuleErrorMessage(
|
|
2139
|
-
if (!
|
|
2174
|
+
generateRuleErrorMessage(rule, position) {
|
|
2175
|
+
if (!rule.operator)
|
|
2140
2176
|
return this.titleStr;
|
|
2141
|
-
const { transformedFormula1
|
|
2142
|
-
return `${this.localeService.t(
|
|
2177
|
+
const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
|
|
2178
|
+
return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
|
|
2143
2179
|
}
|
|
2144
|
-
}
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2180
|
+
};
|
|
2181
|
+
__name(_WholeValidator, "WholeValidator");
|
|
2182
|
+
let WholeValidator = _WholeValidator;
|
|
2183
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2184
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2185
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2186
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
2187
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a9;
|
|
2188
|
+
let DataValidationController = (_a9 = class extends RxDisposable {
|
|
2189
|
+
constructor(_univerInstanceService, _dataValidatorRegistryService, _injector, _selectionManagerService, _sheetInterceptorService, _sheetDataValidationModel) {
|
|
2190
|
+
super(), this._univerInstanceService = _univerInstanceService, this._dataValidatorRegistryService = _dataValidatorRegistryService, this._injector = _injector, this._selectionManagerService = _selectionManagerService, this._sheetInterceptorService = _sheetInterceptorService, this._sheetDataValidationModel = _sheetDataValidationModel, this._init();
|
|
2153
2191
|
}
|
|
2154
2192
|
_init() {
|
|
2155
2193
|
this._registerValidators(), this._initCommandInterceptor();
|
|
2156
2194
|
}
|
|
2157
2195
|
_registerValidators() {
|
|
2158
2196
|
[
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
].forEach((
|
|
2169
|
-
const
|
|
2170
|
-
this.disposeWithMe(this._dataValidatorRegistryService.register(
|
|
2197
|
+
AnyValidator,
|
|
2198
|
+
DecimalValidator,
|
|
2199
|
+
WholeValidator,
|
|
2200
|
+
TextLengthValidator,
|
|
2201
|
+
DateValidator,
|
|
2202
|
+
CheckboxValidator,
|
|
2203
|
+
ListValidator,
|
|
2204
|
+
ListMultipleValidator,
|
|
2205
|
+
CustomFormulaValidator
|
|
2206
|
+
].forEach((Validator) => {
|
|
2207
|
+
const validator = this._injector.createInstance(Validator);
|
|
2208
|
+
this.disposeWithMe(this._dataValidatorRegistryService.register(validator)), this.disposeWithMe(toDisposable(() => this._injector.delete(Validator)));
|
|
2171
2209
|
});
|
|
2172
2210
|
}
|
|
2173
2211
|
_initCommandInterceptor() {
|
|
2174
2212
|
this._sheetInterceptorService.interceptCommand({
|
|
2175
|
-
getMutations: (
|
|
2176
|
-
var
|
|
2177
|
-
if (
|
|
2178
|
-
const
|
|
2179
|
-
if (!
|
|
2213
|
+
getMutations: /* @__PURE__ */ __name((commandInfo) => {
|
|
2214
|
+
var _a12;
|
|
2215
|
+
if (commandInfo.id === ClearSelectionAllCommand.id) {
|
|
2216
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), worksheet = workbook.getActiveSheet();
|
|
2217
|
+
if (!worksheet)
|
|
2180
2218
|
throw new Error("No active sheet found");
|
|
2181
|
-
const
|
|
2182
|
-
|
|
2183
|
-
const
|
|
2219
|
+
const subUnitId = worksheet.getSheetId(), selections = (_a12 = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : _a12.map((s) => s.range), ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
2220
|
+
selections && ruleMatrix.removeRange(selections);
|
|
2221
|
+
const diffs = ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, this._injector, "patched");
|
|
2184
2222
|
return {
|
|
2185
|
-
undos:
|
|
2186
|
-
redos:
|
|
2223
|
+
undos: undoMutations,
|
|
2224
|
+
redos: redoMutations
|
|
2187
2225
|
};
|
|
2188
2226
|
}
|
|
2189
2227
|
return {
|
|
2190
2228
|
undos: [],
|
|
2191
2229
|
redos: []
|
|
2192
2230
|
};
|
|
2193
|
-
}
|
|
2231
|
+
}, "getMutations")
|
|
2194
2232
|
});
|
|
2195
2233
|
}
|
|
2196
|
-
};
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
],
|
|
2205
|
-
var
|
|
2206
|
-
for (var
|
|
2207
|
-
(
|
|
2208
|
-
return
|
|
2209
|
-
},
|
|
2210
|
-
let
|
|
2211
|
-
constructor(
|
|
2212
|
-
super(), this._univerInstanceService =
|
|
2234
|
+
}, __name(_a9, "DataValidationController"), _a9);
|
|
2235
|
+
DataValidationController = __decorateClass$2([
|
|
2236
|
+
__decorateParam$2(0, IUniverInstanceService),
|
|
2237
|
+
__decorateParam$2(1, Inject(DataValidatorRegistryService)),
|
|
2238
|
+
__decorateParam$2(2, Inject(Injector)),
|
|
2239
|
+
__decorateParam$2(3, Inject(SheetsSelectionsService)),
|
|
2240
|
+
__decorateParam$2(4, Inject(SheetInterceptorService)),
|
|
2241
|
+
__decorateParam$2(5, Inject(SheetDataValidationModel))
|
|
2242
|
+
], DataValidationController);
|
|
2243
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2244
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2245
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2246
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
2247
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a10;
|
|
2248
|
+
let SheetsDataValidationValidatorService = (_a10 = class extends Disposable {
|
|
2249
|
+
constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
|
|
2250
|
+
super(), this._univerInstanceService = _univerInstanceService, this._sheetDataValidationModel = _sheetDataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._lifecycleService = _lifecycleService, this._initRecalculate();
|
|
2213
2251
|
}
|
|
2214
2252
|
_initRecalculate() {
|
|
2215
|
-
const
|
|
2216
|
-
if (
|
|
2253
|
+
const handleDirtyRanges = /* @__PURE__ */ __name((ranges) => {
|
|
2254
|
+
if (ranges.length === 0)
|
|
2217
2255
|
return;
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
const
|
|
2222
|
-
|
|
2223
|
-
}), Object.entries(
|
|
2224
|
-
Object.entries(
|
|
2225
|
-
(
|
|
2226
|
-
this.validatorRanges(
|
|
2256
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), worksheet = workbook == null ? void 0 : workbook.getActiveSheet(), map = {};
|
|
2257
|
+
ranges.flat().forEach((range) => {
|
|
2258
|
+
map[range.unitId] || (map[range.unitId] = {}), map[range.unitId][range.subUnitId] || (map[range.unitId][range.subUnitId] = []);
|
|
2259
|
+
const workbook2 = this._univerInstanceService.getUnit(range.unitId, UniverInstanceType.UNIVER_SHEET), worksheet2 = workbook2 == null ? void 0 : workbook2.getSheetBySheetId(range.subUnitId);
|
|
2260
|
+
worksheet2 && map[range.unitId][range.subUnitId].push(...range.ranges.map((range2) => Range.transformRange(range2, worksheet2)));
|
|
2261
|
+
}), Object.entries(map).forEach(([unitId, subUnitMap]) => {
|
|
2262
|
+
Object.entries(subUnitMap).forEach(([subUnitId, ranges2]) => {
|
|
2263
|
+
(workbook == null ? void 0 : workbook.getUnitId()) === unitId && (worksheet == null ? void 0 : worksheet.getSheetId()) === subUnitId ? this.validatorRanges(unitId, subUnitId, ranges2) : requestIdleCallback(() => {
|
|
2264
|
+
this.validatorRanges(unitId, subUnitId, ranges2);
|
|
2227
2265
|
});
|
|
2228
2266
|
});
|
|
2229
2267
|
});
|
|
2230
|
-
};
|
|
2231
|
-
this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(
|
|
2232
|
-
}
|
|
2233
|
-
async _validatorByCell(
|
|
2234
|
-
const
|
|
2235
|
-
if (!
|
|
2236
|
-
throw new Error(`row or col is not defined, row: ${
|
|
2237
|
-
const
|
|
2238
|
-
return
|
|
2239
|
-
this._sheetDataValidationModel.validator(
|
|
2240
|
-
|
|
2268
|
+
}, "handleDirtyRanges");
|
|
2269
|
+
this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(bufferWhen(() => this._lifecycleService.lifecycle$.pipe(filter((stage) => stage === LifecycleStages.Rendered)))).subscribe(handleDirtyRanges)), this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(filter(() => this._lifecycleService.stage >= LifecycleStages.Rendered), bufferDebounceTime(20)).subscribe(handleDirtyRanges));
|
|
2270
|
+
}
|
|
2271
|
+
async _validatorByCell(workbook, worksheet, row, col) {
|
|
2272
|
+
const unitId = workbook.getUnitId(), subUnitId = worksheet.getSheetId();
|
|
2273
|
+
if (!Tools.isDefine(row) || !Tools.isDefine(col))
|
|
2274
|
+
throw new Error(`row or col is not defined, row: ${row}, col: ${col}`);
|
|
2275
|
+
const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
|
|
2276
|
+
return rule ? new Promise((resolve) => {
|
|
2277
|
+
this._sheetDataValidationModel.validator(rule, { unitId, subUnitId, row, col, worksheet, workbook }, (status) => {
|
|
2278
|
+
resolve(status);
|
|
2241
2279
|
});
|
|
2242
|
-
}) :
|
|
2243
|
-
}
|
|
2244
|
-
async validatorCell(
|
|
2245
|
-
const
|
|
2246
|
-
if (!
|
|
2247
|
-
throw new Error(`cannot find current workbook, unitId: ${
|
|
2248
|
-
const
|
|
2249
|
-
if (!
|
|
2250
|
-
throw new Error(`cannot find current worksheet, sheetId: ${
|
|
2251
|
-
return this._validatorByCell(
|
|
2252
|
-
}
|
|
2253
|
-
validatorRanges(
|
|
2254
|
-
if (!
|
|
2280
|
+
}) : DataValidationStatus.VALID;
|
|
2281
|
+
}
|
|
2282
|
+
async validatorCell(unitId, subUnitId, row, col) {
|
|
2283
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
2284
|
+
if (!workbook)
|
|
2285
|
+
throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
2286
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
2287
|
+
if (!worksheet)
|
|
2288
|
+
throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
2289
|
+
return this._validatorByCell(workbook, worksheet, row, col);
|
|
2290
|
+
}
|
|
2291
|
+
validatorRanges(unitId, subUnitId, ranges) {
|
|
2292
|
+
if (!ranges.length)
|
|
2255
2293
|
return Promise.resolve([]);
|
|
2256
|
-
const
|
|
2257
|
-
if (!
|
|
2258
|
-
throw new Error(`cannot find current workbook, unitId: ${
|
|
2259
|
-
const
|
|
2260
|
-
if (!
|
|
2261
|
-
throw new Error(`cannot find current worksheet, sheetId: ${
|
|
2262
|
-
return Promise.all(
|
|
2263
|
-
const
|
|
2264
|
-
return
|
|
2265
|
-
|
|
2266
|
-
}),
|
|
2294
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
2295
|
+
if (!workbook)
|
|
2296
|
+
throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
2297
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
2298
|
+
if (!worksheet)
|
|
2299
|
+
throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
2300
|
+
return Promise.all(ranges.map((range) => {
|
|
2301
|
+
const promises = [];
|
|
2302
|
+
return Range.foreach(range, (row, col) => {
|
|
2303
|
+
promises.push(this._validatorByCell(workbook, worksheet, row, col));
|
|
2304
|
+
}), Promise.all(promises);
|
|
2267
2305
|
}));
|
|
2268
2306
|
}
|
|
2269
|
-
async validatorWorksheet(
|
|
2270
|
-
const
|
|
2271
|
-
if (!
|
|
2272
|
-
throw new Error(`cannot find current workbook, unitId: ${
|
|
2273
|
-
const
|
|
2274
|
-
if (!
|
|
2275
|
-
throw new Error(`cannot find current worksheet, sheetId: ${
|
|
2276
|
-
const
|
|
2277
|
-
return await Promise.all(
|
|
2278
|
-
const
|
|
2279
|
-
return
|
|
2280
|
-
|
|
2281
|
-
}),
|
|
2282
|
-
})))), this._dataValidationCacheService.ensureCache(
|
|
2283
|
-
}
|
|
2284
|
-
async validatorWorkbook(
|
|
2285
|
-
const
|
|
2286
|
-
return
|
|
2287
|
-
|
|
2288
|
-
}),
|
|
2289
|
-
}
|
|
2290
|
-
getDataValidations(
|
|
2291
|
-
const
|
|
2292
|
-
return
|
|
2293
|
-
|
|
2294
|
-
const
|
|
2295
|
-
|
|
2307
|
+
async validatorWorksheet(unitId, subUnitId) {
|
|
2308
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
2309
|
+
if (!workbook)
|
|
2310
|
+
throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
2311
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
2312
|
+
if (!worksheet)
|
|
2313
|
+
throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
2314
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
2315
|
+
return await Promise.all(rules.map((rule) => Promise.all(rule.ranges.map((range) => {
|
|
2316
|
+
const promises = [];
|
|
2317
|
+
return Range.foreach(range, (row, col) => {
|
|
2318
|
+
promises.push(this._validatorByCell(workbook, worksheet, row, col));
|
|
2319
|
+
}), promises;
|
|
2320
|
+
})))), this._dataValidationCacheService.ensureCache(unitId, subUnitId);
|
|
2321
|
+
}
|
|
2322
|
+
async validatorWorkbook(unitId) {
|
|
2323
|
+
const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId), results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id))), map = {};
|
|
2324
|
+
return results.forEach((result, i) => {
|
|
2325
|
+
map[sheetIds[i]] = result;
|
|
2326
|
+
}), map;
|
|
2327
|
+
}
|
|
2328
|
+
getDataValidations(unitId, subUnitId, ranges) {
|
|
2329
|
+
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId), ruleIdSet = /* @__PURE__ */ new Set();
|
|
2330
|
+
return ranges.forEach((range) => {
|
|
2331
|
+
Range.foreach(range, (row, col) => {
|
|
2332
|
+
const ruleId = ruleMatrix.getValue(row, col);
|
|
2333
|
+
ruleId && ruleIdSet.add(ruleId);
|
|
2296
2334
|
});
|
|
2297
|
-
}), Array.from(
|
|
2298
|
-
}
|
|
2299
|
-
getDataValidation(
|
|
2300
|
-
return this.getDataValidations(
|
|
2301
|
-
}
|
|
2302
|
-
};
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
],
|
|
2309
|
-
var
|
|
2310
|
-
for (var
|
|
2311
|
-
(
|
|
2312
|
-
return
|
|
2313
|
-
},
|
|
2314
|
-
let
|
|
2315
|
-
constructor(
|
|
2316
|
-
super(), this._config =
|
|
2317
|
-
const { ...
|
|
2335
|
+
}), Array.from(ruleIdSet).map((id) => this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
2336
|
+
}
|
|
2337
|
+
getDataValidation(unitId, subUnitId, ranges) {
|
|
2338
|
+
return this.getDataValidations(unitId, subUnitId, ranges)[0];
|
|
2339
|
+
}
|
|
2340
|
+
}, __name(_a10, "SheetsDataValidationValidatorService"), _a10);
|
|
2341
|
+
SheetsDataValidationValidatorService = __decorateClass$1([
|
|
2342
|
+
__decorateParam$1(0, IUniverInstanceService),
|
|
2343
|
+
__decorateParam$1(1, Inject(SheetDataValidationModel)),
|
|
2344
|
+
__decorateParam$1(2, Inject(DataValidationCacheService)),
|
|
2345
|
+
__decorateParam$1(3, Inject(LifecycleService))
|
|
2346
|
+
], SheetsDataValidationValidatorService);
|
|
2347
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2348
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2349
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2350
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
2351
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a11;
|
|
2352
|
+
let UniverSheetsDataValidationPlugin = (_a11 = class extends Plugin {
|
|
2353
|
+
constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
|
|
2354
|
+
super(), this._config = _config, this._injector = _injector, this._commandService = _commandService, this._configService = _configService;
|
|
2355
|
+
const { ...rest } = merge(
|
|
2318
2356
|
{},
|
|
2319
|
-
|
|
2357
|
+
defaultPluginConfig,
|
|
2320
2358
|
this._config
|
|
2321
2359
|
);
|
|
2322
|
-
this._configService.setConfig(
|
|
2360
|
+
this._configService.setConfig(SHEETS_DATA_VALIDATION_PLUGIN_CONFIG_KEY, rest);
|
|
2323
2361
|
}
|
|
2324
2362
|
onStarting() {
|
|
2325
2363
|
[
|
|
2326
|
-
[
|
|
2327
|
-
[
|
|
2328
|
-
[
|
|
2329
|
-
[
|
|
2330
|
-
[
|
|
2331
|
-
[
|
|
2332
|
-
[
|
|
2333
|
-
[
|
|
2334
|
-
[
|
|
2335
|
-
[
|
|
2336
|
-
].forEach((
|
|
2337
|
-
this._injector.add(
|
|
2364
|
+
[DataValidationCacheService],
|
|
2365
|
+
[DataValidationFormulaService],
|
|
2366
|
+
[DataValidationCustomFormulaService],
|
|
2367
|
+
[SheetsDataValidationValidatorService],
|
|
2368
|
+
[SheetDataValidationModel],
|
|
2369
|
+
[DataValidationController],
|
|
2370
|
+
[DataValidationFormulaController],
|
|
2371
|
+
[SheetDataValidationSheetController],
|
|
2372
|
+
[DataValidationRefRangeController],
|
|
2373
|
+
[DataValidationFormulaRefRangeController]
|
|
2374
|
+
].forEach((dep) => {
|
|
2375
|
+
this._injector.add(dep);
|
|
2338
2376
|
}), [
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
].forEach((
|
|
2347
|
-
this._commandService.registerCommand(
|
|
2348
|
-
}), this._injector.get(
|
|
2377
|
+
AddSheetDataValidationCommand,
|
|
2378
|
+
UpdateSheetDataValidationRangeCommand,
|
|
2379
|
+
UpdateSheetDataValidationSettingCommand,
|
|
2380
|
+
UpdateSheetDataValidationOptionsCommand,
|
|
2381
|
+
RemoveSheetDataValidationCommand,
|
|
2382
|
+
RemoveSheetAllDataValidationCommand,
|
|
2383
|
+
ClearRangeDataValidationCommand
|
|
2384
|
+
].forEach((command) => {
|
|
2385
|
+
this._commandService.registerCommand(command);
|
|
2386
|
+
}), this._injector.get(DataValidationCacheService), this._injector.get(SheetsDataValidationValidatorService), this._injector.get(DataValidationFormulaRefRangeController), this._injector.get(DataValidationRefRangeController);
|
|
2349
2387
|
}
|
|
2350
2388
|
onReady() {
|
|
2351
|
-
this._injector.get(
|
|
2389
|
+
this._injector.get(SheetDataValidationSheetController);
|
|
2352
2390
|
}
|
|
2353
2391
|
onRendered() {
|
|
2354
|
-
this._injector.get(
|
|
2355
|
-
}
|
|
2356
|
-
};
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
],
|
|
2365
|
-
function
|
|
2366
|
-
const
|
|
2392
|
+
this._injector.get(DataValidationController), this._injector.get(DataValidationFormulaController);
|
|
2393
|
+
}
|
|
2394
|
+
}, __name(_a11, "UniverSheetsDataValidationPlugin"), _a11);
|
|
2395
|
+
__publicField2(UniverSheetsDataValidationPlugin, "pluginName", DATA_VALIDATION_PLUGIN_NAME);
|
|
2396
|
+
__publicField2(UniverSheetsDataValidationPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
2397
|
+
UniverSheetsDataValidationPlugin = __decorateClass([
|
|
2398
|
+
DependentOn(UniverDataValidationPlugin),
|
|
2399
|
+
__decorateParam(1, Inject(Injector)),
|
|
2400
|
+
__decorateParam(2, ICommandService),
|
|
2401
|
+
__decorateParam(3, IConfigService)
|
|
2402
|
+
], UniverSheetsDataValidationPlugin);
|
|
2403
|
+
function createDefaultNewRule(accessor) {
|
|
2404
|
+
const currentRanges = accessor.get(SheetsSelectionsService).getCurrentSelections().map((s) => s.range);
|
|
2367
2405
|
return {
|
|
2368
|
-
uid:
|
|
2369
|
-
type:
|
|
2370
|
-
operator:
|
|
2406
|
+
uid: Tools.generateRandomId(6),
|
|
2407
|
+
type: DataValidationType.DECIMAL,
|
|
2408
|
+
operator: DataValidationOperator.EQUAL,
|
|
2371
2409
|
formula1: "100",
|
|
2372
|
-
ranges:
|
|
2410
|
+
ranges: currentRanges != null ? currentRanges : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
|
|
2373
2411
|
};
|
|
2374
2412
|
}
|
|
2413
|
+
__name(createDefaultNewRule, "createDefaultNewRule");
|
|
2375
2414
|
export {
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2415
|
+
AddSheetDataValidationCommand,
|
|
2416
|
+
CHECKBOX_FORMULA_1,
|
|
2417
|
+
CHECKBOX_FORMULA_2,
|
|
2418
|
+
CheckboxValidator,
|
|
2419
|
+
ClearRangeDataValidationCommand,
|
|
2420
|
+
DATA_VALIDATION_PLUGIN_NAME,
|
|
2421
|
+
DataValidationCacheService,
|
|
2422
|
+
DataValidationCustomFormulaService,
|
|
2423
|
+
DataValidationFormulaController,
|
|
2424
|
+
DataValidationFormulaService,
|
|
2425
|
+
DateValidator,
|
|
2426
|
+
ListMultipleValidator,
|
|
2427
|
+
ListValidator,
|
|
2428
|
+
RemoveSheetAllDataValidationCommand,
|
|
2429
|
+
RemoveSheetDataValidationCommand,
|
|
2430
|
+
SheetDataValidationModel,
|
|
2431
|
+
SheetsDataValidationValidatorService,
|
|
2432
|
+
UniverSheetsDataValidationPlugin,
|
|
2433
|
+
UpdateSheetDataValidationOptionsCommand,
|
|
2434
|
+
UpdateSheetDataValidationRangeCommand,
|
|
2435
|
+
UpdateSheetDataValidationSettingCommand,
|
|
2436
|
+
createDefaultNewRule,
|
|
2437
|
+
deserializeListOptions,
|
|
2438
|
+
getCellValueOrigin,
|
|
2439
|
+
getDataValidationCellValue,
|
|
2440
|
+
getDataValidationDiffMutations,
|
|
2441
|
+
getFormulaCellData,
|
|
2442
|
+
getFormulaResult,
|
|
2443
|
+
isLegalFormulaResult,
|
|
2444
|
+
serializeListOptions,
|
|
2445
|
+
transformCheckboxValue
|
|
2407
2446
|
};
|