@univerjs/sheets-data-validation 0.4.1 → 0.4.2-nightly.202410301606
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/dv-validator-service-9VDfOza1.mjs +2032 -0
- package/lib/es/facade.js +654 -0
- package/lib/es/index.js +163 -2077
- package/lib/types/facade/f-data-validation-builder.d.ts +247 -0
- package/lib/types/facade/f-data-validation.d.ts +88 -0
- package/lib/types/facade/f-range.d.ts +33 -0
- package/lib/types/facade/f-univer.d.ts +6 -0
- package/lib/types/facade/f-workbook.d.ts +66 -0
- package/lib/types/facade/f-worksheet.d.ts +20 -0
- package/lib/types/facade/index.d.ts +2 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/models/rule-matrix.d.ts +1 -0
- package/lib/types/utils/formula.d.ts +1 -0
- package/lib/types/validators/any-validator.d.ts +12 -0
- package/lib/types/validators/custom-validator.d.ts +1 -0
- package/lib/types/validators/decimal-validator.d.ts +1 -0
- package/lib/types/validators/whole-validator.d.ts +1 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +14 -18
- package/LICENSE +0 -176
- package/lib/cjs/index.js +0 -1
package/lib/es/index.js
CHANGED
|
@@ -2,1510 +2,20 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
15
|
-
return kind && result && __defProp$9(target, key, result), result;
|
|
16
|
-
}, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a;
|
|
17
|
-
let DataValidationCacheService = (_a = class extends Disposable {
|
|
18
|
-
constructor(_commandService) {
|
|
19
|
-
super();
|
|
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._initDirtyRanges();
|
|
24
|
-
}
|
|
25
|
-
_initDirtyRanges() {
|
|
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._dirtyRanges$.next({
|
|
33
|
-
unitId,
|
|
34
|
-
subUnitId,
|
|
35
|
-
ranges: [range]
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
_ensureCache(unitId, subUnitId) {
|
|
42
|
-
let unitMap = this._cacheMatrix.get(unitId);
|
|
43
|
-
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._cacheMatrix.set(unitId, unitMap));
|
|
44
|
-
let cacheMatrix = unitMap.get(subUnitId);
|
|
45
|
-
return cacheMatrix || (cacheMatrix = new ObjectMatrix(), unitMap.set(subUnitId, cacheMatrix)), cacheMatrix;
|
|
46
|
-
}
|
|
47
|
-
ensureCache(unitId, subUnitId) {
|
|
48
|
-
return this._ensureCache(unitId, subUnitId);
|
|
49
|
-
}
|
|
50
|
-
addRule(unitId, subUnitId, rule) {
|
|
51
|
-
this.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
52
|
-
}
|
|
53
|
-
removeRule(unitId, subUnitId, rule) {
|
|
54
|
-
this._deleteRange(unitId, subUnitId, rule.ranges);
|
|
55
|
-
}
|
|
56
|
-
updateRuleRanges(unitId, subUnitId, ruleId, newRanges, oldRanges) {
|
|
57
|
-
const cache = this._ensureCache(unitId, subUnitId);
|
|
58
|
-
oldRanges.forEach((range) => {
|
|
59
|
-
Range.foreach(range, (row, col) => {
|
|
60
|
-
const item = cache.getValue(row, col);
|
|
61
|
-
item && (item.temp = !0);
|
|
62
|
-
});
|
|
63
|
-
}), newRanges.forEach((range) => {
|
|
64
|
-
Range.foreach(range, (row, col) => {
|
|
65
|
-
const item = cache.getValue(row, col);
|
|
66
|
-
item && item.ruleId === ruleId ? item.temp = !1 : cache.setValue(row, col, void 0);
|
|
67
|
-
});
|
|
68
|
-
}), oldRanges.forEach((range) => {
|
|
69
|
-
Range.foreach(range, (row, col) => {
|
|
70
|
-
const item = cache.getValue(row, col);
|
|
71
|
-
item && item.temp === !0 && cache.realDeleteValue(row, col);
|
|
72
|
-
});
|
|
73
|
-
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges: [...oldRanges, ...newRanges] });
|
|
74
|
-
}
|
|
75
|
-
markRangeDirty(unitId, subUnitId, ranges) {
|
|
76
|
-
const cache = this._ensureCache(unitId, subUnitId);
|
|
77
|
-
ranges.forEach((range) => {
|
|
78
|
-
Range.foreach(range, (row, col) => {
|
|
79
|
-
cache.setValue(row, col, void 0);
|
|
80
|
-
});
|
|
81
|
-
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
|
|
82
|
-
}
|
|
83
|
-
markCellDirty(unitId, subUnitId, row, col) {
|
|
84
|
-
this._ensureCache(unitId, subUnitId).setValue(row, col, void 0), this._dirtyRanges$.next({ unitId, subUnitId, ranges: [{ startRow: row, startColumn: col, endRow: row, endColumn: col }] });
|
|
85
|
-
}
|
|
86
|
-
_deleteRange(unitId, subUnitId, ranges) {
|
|
87
|
-
const cache = this._ensureCache(unitId, subUnitId);
|
|
88
|
-
ranges.forEach((range) => {
|
|
89
|
-
Range.foreach(range, (row, col) => {
|
|
90
|
-
cache.realDeleteValue(row, col);
|
|
91
|
-
});
|
|
92
|
-
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
|
|
93
|
-
}
|
|
94
|
-
getValue(unitId, subUnitId, row, col) {
|
|
95
|
-
return this._ensureCache(unitId, subUnitId).getValue(row, col);
|
|
96
|
-
}
|
|
97
|
-
setValue(unitId, subUnitId, row, col, value) {
|
|
98
|
-
return this._ensureCache(unitId, subUnitId).setValue(row, col, value);
|
|
99
|
-
}
|
|
100
|
-
}, __name(_a, "DataValidationCacheService"), _a);
|
|
101
|
-
DataValidationCacheService = __decorateClass$9([
|
|
102
|
-
__decorateParam$9(0, Inject(ICommandService))
|
|
103
|
-
], DataValidationCacheService);
|
|
104
|
-
var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
105
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
106
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
107
|
-
return kind && result && __defProp$8(target, key, result), result;
|
|
108
|
-
}, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8");
|
|
109
|
-
function transformFormula(lexerTreeBuilder, formula, originRow, originCol, targetRow, targetCol) {
|
|
110
|
-
return lexerTreeBuilder.moveFormulaRefOffset(formula, targetCol - originCol, targetRow - originRow);
|
|
111
|
-
}
|
|
112
|
-
__name(transformFormula, "transformFormula");
|
|
113
|
-
var _a2;
|
|
114
|
-
let DataValidationCustomFormulaService = (_a2 = class extends Disposable {
|
|
115
|
-
constructor(_instanceSrv, _registerOtherFormulaService, _lexerTreeBuilder, _dataValidationModel, _dataValidationCacheService, _injector) {
|
|
116
|
-
super();
|
|
117
|
-
__publicField(this, "_formulaMap", /* @__PURE__ */ new Map());
|
|
118
|
-
/**
|
|
119
|
-
* Map of origin formula of rule
|
|
120
|
-
*/
|
|
121
|
-
__publicField(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
|
|
122
|
-
/**
|
|
123
|
-
* reflect of formulaId to cell, only store transformable formula
|
|
124
|
-
*/
|
|
125
|
-
__publicField(this, "_formulaCellMap", /* @__PURE__ */ new Map());
|
|
126
|
-
this._instanceSrv = _instanceSrv, this._registerOtherFormulaService = _registerOtherFormulaService, this._lexerTreeBuilder = _lexerTreeBuilder, this._dataValidationModel = _dataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._injector = _injector, this._initFormulaResultHandler();
|
|
127
|
-
}
|
|
128
|
-
_initFormulaResultHandler() {
|
|
129
|
-
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
130
|
-
for (const unitId in resultMap) {
|
|
131
|
-
const unitMap = resultMap[unitId];
|
|
132
|
-
if (this._instanceSrv.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
|
|
133
|
-
for (const subUnitId in unitMap) {
|
|
134
|
-
const results = unitMap[subUnitId], { formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
135
|
-
results.forEach((result) => {
|
|
136
|
-
var _a12, _b;
|
|
137
|
-
const ruleInfo = ruleFormulaMap.get((_a12 = result.extra) == null ? void 0 : _a12.ruleId), cellInfo = formulaCellMap.get(result.formulaId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
|
|
138
|
-
rule && ruleInfo && !ruleInfo.isTransformable && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges), cellInfo && this._dataValidationCacheService.markCellDirty(unitId, subUnitId, cellInfo.row, cellInfo.column);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
_ensureMaps(unitId, subUnitId) {
|
|
145
|
-
let formulaUnitMap = this._formulaMap.get(unitId), ruleFormulaUnitMap = this._ruleFormulaMap.get(unitId), formulaCellUnitMap = this._formulaCellMap.get(unitId);
|
|
146
|
-
(!formulaUnitMap || !ruleFormulaUnitMap || !formulaCellUnitMap) && (formulaUnitMap = /* @__PURE__ */ new Map(), ruleFormulaUnitMap = /* @__PURE__ */ new Map(), formulaCellUnitMap = /* @__PURE__ */ new Map(), this._formulaMap.set(unitId, formulaUnitMap), this._ruleFormulaMap.set(unitId, ruleFormulaUnitMap), this._formulaCellMap.set(unitId, formulaCellUnitMap));
|
|
147
|
-
let formulaMap = formulaUnitMap.get(subUnitId), ruleFormulaMap = ruleFormulaUnitMap.get(subUnitId), formulaCellMap = formulaCellUnitMap.get(subUnitId);
|
|
148
|
-
return (!formulaMap || !ruleFormulaMap || !formulaCellMap) && (formulaMap = new ObjectMatrix(), formulaUnitMap.set(subUnitId, formulaMap), ruleFormulaMap = /* @__PURE__ */ new Map(), ruleFormulaUnitMap.set(subUnitId, ruleFormulaMap), formulaCellMap = /* @__PURE__ */ new Map(), formulaCellUnitMap.set(subUnitId, formulaCellMap)), {
|
|
149
|
-
formulaMap,
|
|
150
|
-
ruleFormulaMap,
|
|
151
|
-
formulaCellMap
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
_registerFormula(unitId, subUnitId, ruleId, formulaString) {
|
|
155
|
-
return this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formulaString, { ruleId });
|
|
156
|
-
}
|
|
157
|
-
deleteByRuleId(unitId, subUnitId, ruleId) {
|
|
158
|
-
const { formulaMap, formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId), formulaIdList = /* @__PURE__ */ new Set(), formulaInfo = ruleFormulaMap.get(ruleId);
|
|
159
|
-
!rule || !formulaInfo || (ruleFormulaMap.delete(ruleId), rule.ranges.forEach((range) => {
|
|
160
|
-
Range.foreach(range, (row, col) => {
|
|
161
|
-
const value = formulaMap.getValue(row, col);
|
|
162
|
-
if (value && value.ruleId === ruleId) {
|
|
163
|
-
const { formulaId } = value;
|
|
164
|
-
formulaMap.realDeleteValue(row, col), formulaIdList.add(formulaId), formulaCellMap.delete(formulaId);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, Array.from(formulaIdList.values())));
|
|
168
|
-
}
|
|
169
|
-
_addFormulaByRange(unitId, subUnitId, ruleId, formula, ranges) {
|
|
170
|
-
const { formulaMap, ruleFormulaMap, formulaCellMap } = this._ensureMaps(unitId, subUnitId);
|
|
171
|
-
if (!formula)
|
|
172
|
-
return;
|
|
173
|
-
const originRow = ranges[0].startRow, originCol = ranges[0].startColumn;
|
|
174
|
-
let originFormulaId;
|
|
175
|
-
ranges.forEach((range) => {
|
|
176
|
-
Range.foreach(range, (row, column) => {
|
|
177
|
-
const relativeFormula = transformFormula(
|
|
178
|
-
this._lexerTreeBuilder,
|
|
179
|
-
formula,
|
|
180
|
-
originRow,
|
|
181
|
-
originCol,
|
|
182
|
-
row,
|
|
183
|
-
column
|
|
184
|
-
), formulaId = this._registerFormula(unitId, subUnitId, ruleId, relativeFormula);
|
|
185
|
-
formulaMap.setValue(row, column, {
|
|
186
|
-
formulaId,
|
|
187
|
-
// formulaText: relativeFormula,
|
|
188
|
-
ruleId
|
|
189
|
-
}), formulaCellMap.set(formulaId, { row, column });
|
|
190
|
-
});
|
|
191
|
-
}), ruleFormulaMap.set(ruleId, {
|
|
192
|
-
formula,
|
|
193
|
-
originCol,
|
|
194
|
-
originRow,
|
|
195
|
-
formulaId: originFormulaId,
|
|
196
|
-
isTransformable: !0
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
addRule(unitId, subUnitId, rule) {
|
|
200
|
-
const { ranges, formula1, uid: ruleId, type } = rule;
|
|
201
|
-
type !== DataValidationType.CUSTOM || !formula1 || !isFormulaString(formula1) || this._addFormulaByRange(unitId, subUnitId, ruleId, formula1, ranges);
|
|
202
|
-
}
|
|
203
|
-
updateRuleRanges(unitId, subUnitId, ruleId, oldRanges, newRanges) {
|
|
204
|
-
const { formulaMap, ruleFormulaMap, formulaCellMap } = this._ensureMaps(unitId, subUnitId), info = ruleFormulaMap.get(ruleId);
|
|
205
|
-
if (!info)
|
|
206
|
-
return;
|
|
207
|
-
const { formula, originCol, originRow, isTransformable, formulaId } = info, deleteFormulaIdList = /* @__PURE__ */ new Set();
|
|
208
|
-
oldRanges.forEach((range) => {
|
|
209
|
-
Range.foreach(range, (row, col) => {
|
|
210
|
-
const value = formulaMap.getValue(row, col);
|
|
211
|
-
value && value.ruleId === ruleId && (value.temp = !0);
|
|
212
|
-
});
|
|
213
|
-
}), newRanges.forEach((range) => {
|
|
214
|
-
Range.foreach(range, (row, col) => {
|
|
215
|
-
var _a12;
|
|
216
|
-
const oldValue = (_a12 = formulaMap.getValue(row, col)) != null ? _a12 : {};
|
|
217
|
-
if (oldValue.ruleId !== ruleId) {
|
|
218
|
-
const oldRuleFormula = ruleFormulaMap.get(oldValue.ruleId);
|
|
219
|
-
if (oldRuleFormula != null && oldRuleFormula.isTransformable && deleteFormulaIdList.add(oldValue.formulaId), isTransformable) {
|
|
220
|
-
const relativeText = transformFormula(this._lexerTreeBuilder, formula, originRow, originCol, row, col), formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, relativeText);
|
|
221
|
-
formulaMap.setValue(row, col, {
|
|
222
|
-
ruleId,
|
|
223
|
-
formulaId: formulaId2
|
|
224
|
-
}), formulaCellMap.set(formulaId2, { row, column: col });
|
|
225
|
-
} else
|
|
226
|
-
formulaMap.setValue(row, col, {
|
|
227
|
-
// formulaText: formula,
|
|
228
|
-
ruleId,
|
|
229
|
-
formulaId
|
|
230
|
-
});
|
|
231
|
-
} else
|
|
232
|
-
oldValue.temp = !1;
|
|
233
|
-
});
|
|
234
|
-
}), oldRanges.forEach((range) => {
|
|
235
|
-
Range.foreach(range, (row, col) => {
|
|
236
|
-
const value = formulaMap.getValue(row, col);
|
|
237
|
-
value && value.ruleId === ruleId && value.temp === !0 && (formulaMap.realDeleteValue(row, col), isTransformable && deleteFormulaIdList.add(value.formulaId));
|
|
238
|
-
});
|
|
239
|
-
}), deleteFormulaIdList.forEach((formulaId2) => {
|
|
240
|
-
formulaCellMap.delete(formulaId2);
|
|
241
|
-
}), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, Array.from(deleteFormulaIdList.values()));
|
|
242
|
-
}
|
|
243
|
-
updateRuleFormula(unitId, subUnitId, ruleId, ranges, formula) {
|
|
244
|
-
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap.get(ruleId);
|
|
245
|
-
(!current || current.formula !== formula) && this._addFormulaByRange(unitId, subUnitId, ruleId, formula, ranges);
|
|
246
|
-
}
|
|
247
|
-
getCellFormulaValue(unitId, subUnitId, row, col) {
|
|
248
|
-
const { formulaMap } = this._ensureMaps(unitId, subUnitId), current = formulaMap.getValue(row, col);
|
|
249
|
-
return current ? this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId) : Promise.resolve(void 0);
|
|
250
|
-
}
|
|
251
|
-
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
252
|
-
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
253
|
-
return ruleFormulaMap.get(ruleId);
|
|
254
|
-
}
|
|
255
|
-
}, __name(_a2, "DataValidationCustomFormulaService"), _a2);
|
|
256
|
-
DataValidationCustomFormulaService = __decorateClass$8([
|
|
257
|
-
__decorateParam$8(0, IUniverInstanceService),
|
|
258
|
-
__decorateParam$8(1, Inject(RegisterOtherFormulaService)),
|
|
259
|
-
__decorateParam$8(2, Inject(LexerTreeBuilder)),
|
|
260
|
-
__decorateParam$8(3, Inject(DataValidationModel)),
|
|
261
|
-
__decorateParam$8(4, Inject(DataValidationCacheService)),
|
|
262
|
-
__decorateParam$8(5, Inject(Injector))
|
|
263
|
-
], DataValidationCustomFormulaService);
|
|
264
|
-
var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
265
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
266
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
267
|
-
return kind && result && __defProp$7(target, key, result), result;
|
|
268
|
-
}, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a3;
|
|
269
|
-
let DataValidationFormulaService = (_a3 = class extends Disposable {
|
|
270
|
-
constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel) {
|
|
271
|
-
super();
|
|
272
|
-
__publicField(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
|
|
273
|
-
this._instanceService = _instanceService, this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationModel = _dataValidationModel, this._initFormulaResultHandler();
|
|
274
|
-
}
|
|
275
|
-
_initFormulaResultHandler() {
|
|
276
|
-
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
277
|
-
for (const unitId in resultMap) {
|
|
278
|
-
const unitMap = resultMap[unitId];
|
|
279
|
-
if (this._instanceService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
|
|
280
|
-
for (const subUnitId in unitMap) {
|
|
281
|
-
const results = unitMap[subUnitId], formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
|
|
282
|
-
results.forEach((result) => {
|
|
283
|
-
var _a12, _b;
|
|
284
|
-
if (formulaMap.get((_a12 = result.extra) == null ? void 0 : _a12.ruleId)) {
|
|
285
|
-
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
|
|
286
|
-
rule && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}));
|
|
292
|
-
}
|
|
293
|
-
_ensureRuleFormulaMap(unitId, subUnitId) {
|
|
294
|
-
let unitMap = this._formulaRuleMap.get(unitId);
|
|
295
|
-
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._formulaRuleMap.set(unitId, unitMap));
|
|
296
|
-
let subUnitMap = unitMap.get(subUnitId);
|
|
297
|
-
return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
|
|
298
|
-
}
|
|
299
|
-
addRule(unitId, subUnitId, ruleId, formula1, formula2) {
|
|
300
|
-
const isFormula1Legal = isFormulaString(formula1), isFormula2Legal = isFormulaString(formula2);
|
|
301
|
-
if (!isFormula1Legal && !isFormula2Legal)
|
|
302
|
-
return;
|
|
303
|
-
const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId), item = [void 0, void 0];
|
|
304
|
-
if (isFormula1Legal) {
|
|
305
|
-
const id = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula1, { ruleId });
|
|
306
|
-
item[0] = { id, text: formula1 };
|
|
307
|
-
}
|
|
308
|
-
if (isFormula2Legal) {
|
|
309
|
-
const id = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula2, { ruleId });
|
|
310
|
-
item[1] = { id, text: formula2 };
|
|
311
|
-
}
|
|
312
|
-
formulaRuleMap.set(ruleId, item);
|
|
313
|
-
}
|
|
314
|
-
removeRule(unitId, subUnitId, ruleId) {
|
|
315
|
-
const item = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
316
|
-
if (!item)
|
|
317
|
-
return;
|
|
318
|
-
const [formula1, formula2] = item, idList = [formula1 == null ? void 0 : formula1.id, formula2 == null ? void 0 : formula2.id].filter(Boolean);
|
|
319
|
-
idList.length && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, idList);
|
|
320
|
-
}
|
|
321
|
-
updateRuleFormulaText(unitId, subUnitId, ruleId, formula1, formula2) {
|
|
322
|
-
const item = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
323
|
-
if (!item) {
|
|
324
|
-
this.addRule(unitId, subUnitId, ruleId, formula1, formula2);
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
const [oldFormula1, oldFormula2] = item;
|
|
328
|
-
if ((oldFormula1 == null ? void 0 : oldFormula1.text) !== formula1)
|
|
329
|
-
if (oldFormula1 && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [oldFormula1.id]), isFormulaString(formula1)) {
|
|
330
|
-
const formulaId = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula1, { ruleId });
|
|
331
|
-
item[0] = {
|
|
332
|
-
text: formula1,
|
|
333
|
-
id: formulaId
|
|
334
|
-
};
|
|
335
|
-
} else
|
|
336
|
-
item[0] = void 0;
|
|
337
|
-
if ((oldFormula2 == null ? void 0 : oldFormula2.text) !== formula2)
|
|
338
|
-
if (oldFormula2 && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [oldFormula2.id]), isFormulaString(formula2)) {
|
|
339
|
-
const formulaId = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula2, { ruleId });
|
|
340
|
-
item[1] = {
|
|
341
|
-
text: formula2,
|
|
342
|
-
id: formulaId
|
|
343
|
-
};
|
|
344
|
-
} else
|
|
345
|
-
item[1] = void 0;
|
|
346
|
-
}
|
|
347
|
-
getRuleFormulaResult(unitId, subUnitId, ruleId) {
|
|
348
|
-
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
349
|
-
if (!formulaInfo)
|
|
350
|
-
return Promise.resolve(null);
|
|
351
|
-
const getResult = /* @__PURE__ */ __name(async (info) => info && this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, info.id), "getResult");
|
|
352
|
-
return Promise.all([
|
|
353
|
-
getResult(formulaInfo[0]),
|
|
354
|
-
getResult(formulaInfo[1])
|
|
355
|
-
]);
|
|
356
|
-
}
|
|
357
|
-
getRuleFormulaResultSync(unitId, subUnitId, ruleId) {
|
|
358
|
-
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
359
|
-
if (formulaInfo)
|
|
360
|
-
return formulaInfo.map((i) => {
|
|
361
|
-
if (i)
|
|
362
|
-
return this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, i.id);
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
366
|
-
return this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
367
|
-
}
|
|
368
|
-
}, __name(_a3, "DataValidationFormulaService"), _a3);
|
|
369
|
-
DataValidationFormulaService = __decorateClass$7([
|
|
370
|
-
__decorateParam$7(0, IUniverInstanceService),
|
|
371
|
-
__decorateParam$7(1, Inject(RegisterOtherFormulaService)),
|
|
372
|
-
__decorateParam$7(2, Inject(DataValidationCacheService)),
|
|
373
|
-
__decorateParam$7(3, Inject(DataValidationModel))
|
|
374
|
-
], DataValidationFormulaService);
|
|
375
|
-
function getCellValueOrigin(cell) {
|
|
376
|
-
return getOriginCellValue(cell);
|
|
377
|
-
}
|
|
378
|
-
__name(getCellValueOrigin, "getCellValueOrigin");
|
|
379
|
-
function getStringCellValue(cell) {
|
|
380
|
-
var _a12;
|
|
381
|
-
return String((_a12 = getCellValueOrigin(cell)) != null ? _a12 : "");
|
|
382
|
-
}
|
|
383
|
-
__name(getStringCellValue, "getStringCellValue");
|
|
384
|
-
var _a4;
|
|
385
|
-
const Interval = (_a4 = class {
|
|
386
|
-
/**
|
|
387
|
-
* Accept two comparable values and creates new instance of interval
|
|
388
|
-
* Predicate Interval.comparable_less(low, high) supposed to return true on these values
|
|
389
|
-
* @param low
|
|
390
|
-
* @param high
|
|
391
|
-
*/
|
|
392
|
-
constructor(low, high) {
|
|
393
|
-
this.low = low, this.high = high;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Clone interval
|
|
397
|
-
* @returns {Interval}
|
|
398
|
-
*/
|
|
399
|
-
clone() {
|
|
400
|
-
return new _a4(this.low, this.high);
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Propery max returns clone of this interval
|
|
404
|
-
* @returns {Interval}
|
|
405
|
-
*/
|
|
406
|
-
get max() {
|
|
407
|
-
return this.clone();
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Predicate returns true is this interval less than other interval
|
|
411
|
-
* @param other_interval
|
|
412
|
-
* @returns {boolean}
|
|
413
|
-
*/
|
|
414
|
-
less_than(other_interval) {
|
|
415
|
-
return this.low < other_interval.low || this.low === other_interval.low && this.high < other_interval.high;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Predicate returns true is this interval equals to other interval
|
|
419
|
-
* @param other_interval
|
|
420
|
-
* @returns {boolean}
|
|
421
|
-
*/
|
|
422
|
-
equal_to(other_interval) {
|
|
423
|
-
return this.low === other_interval.low && this.high === other_interval.high;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Predicate returns true if this interval intersects other interval
|
|
427
|
-
* @param other_interval
|
|
428
|
-
* @returns {boolean}
|
|
429
|
-
*/
|
|
430
|
-
intersect(other_interval) {
|
|
431
|
-
return !this.not_intersect(other_interval);
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Predicate returns true if this interval does not intersect other interval
|
|
435
|
-
* @param other_interval
|
|
436
|
-
* @returns {boolean}
|
|
437
|
-
*/
|
|
438
|
-
not_intersect(other_interval) {
|
|
439
|
-
return this.high < other_interval.low || other_interval.high < this.low;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Returns new interval merged with other interval
|
|
443
|
-
* @param {Interval} other_interval - Other interval to merge with
|
|
444
|
-
* @returns {Interval}
|
|
445
|
-
*/
|
|
446
|
-
merge(other_interval) {
|
|
447
|
-
return new _a4(
|
|
448
|
-
this.low === void 0 ? other_interval.low : this.low < other_interval.low ? this.low : other_interval.low,
|
|
449
|
-
this.high === void 0 ? other_interval.high : this.high > other_interval.high ? this.high : other_interval.high
|
|
450
|
-
);
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Returns how key should return
|
|
454
|
-
*/
|
|
455
|
-
output() {
|
|
456
|
-
return [this.low, this.high];
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Function returns maximum between two comparable values
|
|
460
|
-
* @param interval1
|
|
461
|
-
* @param interval2
|
|
462
|
-
* @returns {Interval}
|
|
463
|
-
*/
|
|
464
|
-
static comparable_max(interval1, interval2) {
|
|
465
|
-
return interval1.merge(interval2);
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Predicate returns true if first value less than second value
|
|
469
|
-
* @param val1
|
|
470
|
-
* @param val2
|
|
471
|
-
* @returns {boolean}
|
|
472
|
-
*/
|
|
473
|
-
static comparable_less_than(val1, val2) {
|
|
474
|
-
return val1 < val2;
|
|
475
|
-
}
|
|
476
|
-
}, __name(_a4, "Interval"), _a4), RB_TREE_COLOR_RED = 0, RB_TREE_COLOR_BLACK = 1, _Node = class _Node {
|
|
477
|
-
constructor(key = void 0, value = void 0, left = null, right = null, parent = null, color = RB_TREE_COLOR_BLACK) {
|
|
478
|
-
if (this.left = left, this.right = right, this.parent = parent, this.color = color, this.item = { key, value }, key && key instanceof Array && key.length === 2 && !Number.isNaN(key[0]) && !Number.isNaN(key[1])) {
|
|
479
|
-
let [low, high] = key;
|
|
480
|
-
low > high && ([low, high] = [high, low]), this.item.key = new Interval(low, high);
|
|
481
|
-
}
|
|
482
|
-
this.max = this.item.key ? this.item.key.max : void 0;
|
|
483
|
-
}
|
|
484
|
-
isNil() {
|
|
485
|
-
return this.item.key === void 0 && this.item.value === void 0 && this.left === null && this.right === null && this.color === RB_TREE_COLOR_BLACK;
|
|
486
|
-
}
|
|
487
|
-
_value_less_than(other_node) {
|
|
488
|
-
return this.item.value && other_node.item.value && this.item.value.less_than ? this.item.value.less_than(other_node.item.value) : this.item.value < other_node.item.value;
|
|
489
|
-
}
|
|
490
|
-
less_than(other_node) {
|
|
491
|
-
return this.item.value === this.item.key && other_node.item.value === other_node.item.key ? this.item.key.less_than(other_node.item.key) : this.item.key.less_than(other_node.item.key) || this.item.key.equal_to(other_node.item.key) && this._value_less_than(other_node);
|
|
492
|
-
}
|
|
493
|
-
_value_equal(other_node) {
|
|
494
|
-
return this.item.value && other_node.item.value && this.item.value.equal_to ? this.item.value.equal_to(other_node.item.value) : this.item.value === other_node.item.value;
|
|
495
|
-
}
|
|
496
|
-
equal_to(other_node) {
|
|
497
|
-
return this.item.value === this.item.key && other_node.item.value === other_node.item.key ? this.item.key.equal_to(other_node.item.key) : this.item.key.equal_to(other_node.item.key) && this._value_equal(other_node);
|
|
498
|
-
}
|
|
499
|
-
intersect(other_node) {
|
|
500
|
-
return this.item.key.intersect(other_node.item.key);
|
|
501
|
-
}
|
|
502
|
-
copy_data(other_node) {
|
|
503
|
-
this.item.key = other_node.item.key, this.item.value = other_node.item.value;
|
|
504
|
-
}
|
|
505
|
-
update_max() {
|
|
506
|
-
if (this.max = this.item.key ? this.item.key.max : void 0, this.right && this.right.max) {
|
|
507
|
-
const comparable_max = this.item.key.constructor.comparable_max;
|
|
508
|
-
this.max = comparable_max(this.max, this.right.max);
|
|
509
|
-
}
|
|
510
|
-
if (this.left && this.left.max) {
|
|
511
|
-
const comparable_max = this.item.key.constructor.comparable_max;
|
|
512
|
-
this.max = comparable_max(this.max, this.left.max);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
// Other_node does not intersect any node of left subtree, if this.left.max < other_node.item.key.low
|
|
516
|
-
not_intersect_left_subtree(search_node) {
|
|
517
|
-
const comparable_less_than = this.item.key.constructor.comparable_less_than;
|
|
518
|
-
let high = this.left.max.high !== void 0 ? this.left.max.high : this.left.max;
|
|
519
|
-
return comparable_less_than(high, search_node.item.key.low);
|
|
520
|
-
}
|
|
521
|
-
// Other_node does not intersect right subtree if other_node.item.key.high < this.right.key.low
|
|
522
|
-
not_intersect_right_subtree(search_node) {
|
|
523
|
-
const comparable_less_than = this.item.key.constructor.comparable_less_than;
|
|
524
|
-
let low = this.right.max.low !== void 0 ? this.right.max.low : this.right.item.key.low;
|
|
525
|
-
return comparable_less_than(search_node.item.key.high, low);
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
__name(_Node, "Node");
|
|
529
|
-
let Node = _Node;
|
|
530
|
-
const _IntervalTree = class _IntervalTree {
|
|
531
|
-
/**
|
|
532
|
-
* Construct new empty instance of IntervalTree
|
|
533
|
-
*/
|
|
534
|
-
constructor() {
|
|
535
|
-
this.root = null, this.nil_node = new Node();
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Returns number of items stored in the interval tree
|
|
539
|
-
* @returns {number}
|
|
540
|
-
*/
|
|
541
|
-
get size() {
|
|
542
|
-
let count = 0;
|
|
543
|
-
return this.tree_walk(this.root, () => count++), count;
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Returns array of sorted keys in the ascending order
|
|
547
|
-
* @returns {Array}
|
|
548
|
-
*/
|
|
549
|
-
get keys() {
|
|
550
|
-
let res = [];
|
|
551
|
-
return this.tree_walk(this.root, (node) => res.push(
|
|
552
|
-
node.item.key.output ? node.item.key.output() : node.item.key
|
|
553
|
-
)), res;
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Return array of values in the ascending keys order
|
|
557
|
-
* @returns {Array}
|
|
558
|
-
*/
|
|
559
|
-
get values() {
|
|
560
|
-
let res = [];
|
|
561
|
-
return this.tree_walk(this.root, (node) => res.push(node.item.value)), res;
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Returns array of items (<key,value> pairs) in the ascended keys order
|
|
565
|
-
* @returns {Array}
|
|
566
|
-
*/
|
|
567
|
-
get items() {
|
|
568
|
-
let res = [];
|
|
569
|
-
return this.tree_walk(this.root, (node) => res.push({
|
|
570
|
-
key: node.item.key.output ? node.item.key.output() : node.item.key,
|
|
571
|
-
value: node.item.value
|
|
572
|
-
})), res;
|
|
573
|
-
}
|
|
574
|
-
/**
|
|
575
|
-
* Returns true if tree is empty
|
|
576
|
-
* @returns {boolean}
|
|
577
|
-
*/
|
|
578
|
-
isEmpty() {
|
|
579
|
-
return this.root == null || this.root === this.nil_node;
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* Clear tree
|
|
583
|
-
*/
|
|
584
|
-
clear() {
|
|
585
|
-
this.root = null;
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* Insert new item into interval tree
|
|
589
|
-
* @param {Interval} key - interval object or array of two numbers [low, high]
|
|
590
|
-
* @param {any} value - value representing any object (optional)
|
|
591
|
-
* @returns {Node} returns reference to inserted node as an object {key:interval, value: value}
|
|
592
|
-
*/
|
|
593
|
-
insert(key, value = key) {
|
|
594
|
-
if (key === void 0) return;
|
|
595
|
-
let insert_node = new Node(key, value, this.nil_node, this.nil_node, null, RB_TREE_COLOR_RED);
|
|
596
|
-
return this.tree_insert(insert_node), this.recalc_max(insert_node), insert_node;
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Returns true if item {key,value} exist in the tree
|
|
600
|
-
* @param {Interval} key - interval correspondent to keys stored in the tree
|
|
601
|
-
* @param {any} value - value object to be checked
|
|
602
|
-
* @returns {boolean} true if item {key, value} exist in the tree, false otherwise
|
|
603
|
-
*/
|
|
604
|
-
exist(key, value = key) {
|
|
605
|
-
let search_node = new Node(key, value);
|
|
606
|
-
return !!this.tree_search(this.root, search_node);
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Remove entry {key, value} from the tree
|
|
610
|
-
* @param {Interval} key - interval correspondent to keys stored in the tree
|
|
611
|
-
* @param {any} value - value object
|
|
612
|
-
* @returns {boolean} true if item {key, value} deleted, false if not found
|
|
613
|
-
*/
|
|
614
|
-
remove(key, value = key) {
|
|
615
|
-
let search_node = new Node(key, value), delete_node = this.tree_search(this.root, search_node);
|
|
616
|
-
return delete_node && this.tree_delete(delete_node), delete_node;
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* Returns array of entry values which keys intersect with given interval <br/>
|
|
620
|
-
* If no values stored in the tree, returns array of keys which intersect given interval
|
|
621
|
-
* @param {Interval} interval - search interval, or tuple [low, high]
|
|
622
|
-
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
|
|
623
|
-
* @returns {Array}
|
|
624
|
-
*/
|
|
625
|
-
search(interval, outputMapperFn = (value, key) => value === key ? key.output() : value) {
|
|
626
|
-
let search_node = new Node(interval), resp_nodes = [];
|
|
627
|
-
return this.tree_search_interval(this.root, search_node, resp_nodes), resp_nodes.map((node) => outputMapperFn(node.item.value, node.item.key));
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* Returns true if intersection between given and any interval stored in the tree found
|
|
631
|
-
* @param {Interval} interval - search interval or tuple [low, high]
|
|
632
|
-
* @returns {boolean}
|
|
633
|
-
*/
|
|
634
|
-
intersect_any(interval) {
|
|
635
|
-
let search_node = new Node(interval);
|
|
636
|
-
return this.tree_find_any_interval(this.root, search_node);
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Tree visitor. For each node implement a callback function. <br/>
|
|
640
|
-
* Method calls a callback function with two parameters (key, value)
|
|
641
|
-
* @param visitor(key,value) - function to be called for each tree item
|
|
642
|
-
*/
|
|
643
|
-
forEach(visitor) {
|
|
644
|
-
this.tree_walk(this.root, (node) => visitor(node.item.key, node.item.value));
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Value Mapper. Walk through every node and map node value to another value
|
|
648
|
-
* @param callback(value,key) - function to be called for each tree item
|
|
649
|
-
*/
|
|
650
|
-
map(callback) {
|
|
651
|
-
const tree = new _IntervalTree();
|
|
652
|
-
return this.tree_walk(this.root, (node) => tree.insert(node.item.key, callback(node.item.value, node.item.key))), tree;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
|
|
656
|
-
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
|
|
657
|
-
* @returns {Iterator}
|
|
658
|
-
*/
|
|
659
|
-
*iterate(interval, outputMapperFn = (value, key) => value === key ? key.output() : value) {
|
|
660
|
-
let node;
|
|
661
|
-
for (interval ? node = this.tree_search_nearest_forward(this.root, new Node(interval)) : this.root && (node = this.local_minimum(this.root)); node; )
|
|
662
|
-
yield outputMapperFn(node.item.value, node.item.key), node = this.tree_successor(node);
|
|
663
|
-
}
|
|
664
|
-
recalc_max(node) {
|
|
665
|
-
let node_current = node;
|
|
666
|
-
for (; node_current.parent != null; )
|
|
667
|
-
node_current.parent.update_max(), node_current = node_current.parent;
|
|
668
|
-
}
|
|
669
|
-
tree_insert(insert_node) {
|
|
670
|
-
let current_node = this.root, parent_node = null;
|
|
671
|
-
if (this.root == null || this.root === this.nil_node)
|
|
672
|
-
this.root = insert_node;
|
|
673
|
-
else {
|
|
674
|
-
for (; current_node !== this.nil_node; )
|
|
675
|
-
parent_node = current_node, insert_node.less_than(current_node) ? current_node = current_node.left : current_node = current_node.right;
|
|
676
|
-
insert_node.parent = parent_node, insert_node.less_than(parent_node) ? parent_node.left = insert_node : parent_node.right = insert_node;
|
|
677
|
-
}
|
|
678
|
-
this.insert_fixup(insert_node);
|
|
679
|
-
}
|
|
680
|
-
// After insertion insert_node may have red-colored parent, and this is a single possible violation
|
|
681
|
-
// Go upwords to the root and re-color until violation will be resolved
|
|
682
|
-
insert_fixup(insert_node) {
|
|
683
|
-
let current_node, uncle_node;
|
|
684
|
-
for (current_node = insert_node; current_node !== this.root && current_node.parent.color === RB_TREE_COLOR_RED; )
|
|
685
|
-
current_node.parent === current_node.parent.parent.left ? (uncle_node = current_node.parent.parent.right, uncle_node.color === RB_TREE_COLOR_RED ? (current_node.parent.color = RB_TREE_COLOR_BLACK, uncle_node.color = RB_TREE_COLOR_BLACK, current_node.parent.parent.color = RB_TREE_COLOR_RED, current_node = current_node.parent.parent) : (current_node === current_node.parent.right && (current_node = current_node.parent, this.rotate_left(current_node)), current_node.parent.color = RB_TREE_COLOR_BLACK, current_node.parent.parent.color = RB_TREE_COLOR_RED, this.rotate_right(current_node.parent.parent))) : (uncle_node = current_node.parent.parent.left, uncle_node.color === RB_TREE_COLOR_RED ? (current_node.parent.color = RB_TREE_COLOR_BLACK, uncle_node.color = RB_TREE_COLOR_BLACK, current_node.parent.parent.color = RB_TREE_COLOR_RED, current_node = current_node.parent.parent) : (current_node === current_node.parent.left && (current_node = current_node.parent, this.rotate_right(current_node)), current_node.parent.color = RB_TREE_COLOR_BLACK, current_node.parent.parent.color = RB_TREE_COLOR_RED, this.rotate_left(current_node.parent.parent)));
|
|
686
|
-
this.root.color = RB_TREE_COLOR_BLACK;
|
|
687
|
-
}
|
|
688
|
-
tree_delete(delete_node) {
|
|
689
|
-
let cut_node, fix_node;
|
|
690
|
-
delete_node.left === this.nil_node || delete_node.right === this.nil_node ? cut_node = delete_node : cut_node = this.tree_successor(delete_node), cut_node.left !== this.nil_node ? fix_node = cut_node.left : fix_node = cut_node.right, fix_node.parent = cut_node.parent, cut_node === this.root ? this.root = fix_node : (cut_node === cut_node.parent.left ? cut_node.parent.left = fix_node : cut_node.parent.right = fix_node, cut_node.parent.update_max()), this.recalc_max(fix_node), cut_node !== delete_node && (delete_node.copy_data(cut_node), delete_node.update_max(), this.recalc_max(delete_node)), /*fix_node != this.nil_node && */
|
|
691
|
-
cut_node.color === RB_TREE_COLOR_BLACK && this.delete_fixup(fix_node);
|
|
692
|
-
}
|
|
693
|
-
delete_fixup(fix_node) {
|
|
694
|
-
let current_node = fix_node, brother_node;
|
|
695
|
-
for (; current_node !== this.root && current_node.parent != null && current_node.color === RB_TREE_COLOR_BLACK; )
|
|
696
|
-
current_node === current_node.parent.left ? (brother_node = current_node.parent.right, brother_node.color === RB_TREE_COLOR_RED && (brother_node.color = RB_TREE_COLOR_BLACK, current_node.parent.color = RB_TREE_COLOR_RED, this.rotate_left(current_node.parent), brother_node = current_node.parent.right), brother_node.left.color === RB_TREE_COLOR_BLACK && brother_node.right.color === RB_TREE_COLOR_BLACK ? (brother_node.color = RB_TREE_COLOR_RED, current_node = current_node.parent) : (brother_node.right.color === RB_TREE_COLOR_BLACK && (brother_node.color = RB_TREE_COLOR_RED, brother_node.left.color = RB_TREE_COLOR_BLACK, this.rotate_right(brother_node), brother_node = current_node.parent.right), brother_node.color = current_node.parent.color, current_node.parent.color = RB_TREE_COLOR_BLACK, brother_node.right.color = RB_TREE_COLOR_BLACK, this.rotate_left(current_node.parent), current_node = this.root)) : (brother_node = current_node.parent.left, brother_node.color === RB_TREE_COLOR_RED && (brother_node.color = RB_TREE_COLOR_BLACK, current_node.parent.color = RB_TREE_COLOR_RED, this.rotate_right(current_node.parent), brother_node = current_node.parent.left), brother_node.left.color === RB_TREE_COLOR_BLACK && brother_node.right.color === RB_TREE_COLOR_BLACK ? (brother_node.color = RB_TREE_COLOR_RED, current_node = current_node.parent) : (brother_node.left.color === RB_TREE_COLOR_BLACK && (brother_node.color = RB_TREE_COLOR_RED, brother_node.right.color = RB_TREE_COLOR_BLACK, this.rotate_left(brother_node), brother_node = current_node.parent.left), brother_node.color = current_node.parent.color, current_node.parent.color = RB_TREE_COLOR_BLACK, brother_node.left.color = RB_TREE_COLOR_BLACK, this.rotate_right(current_node.parent), current_node = this.root));
|
|
697
|
-
current_node.color = RB_TREE_COLOR_BLACK;
|
|
698
|
-
}
|
|
699
|
-
tree_search(node, search_node) {
|
|
700
|
-
if (!(node == null || node === this.nil_node))
|
|
701
|
-
return search_node.equal_to(node) ? node : search_node.less_than(node) ? this.tree_search(node.left, search_node) : this.tree_search(node.right, search_node);
|
|
702
|
-
}
|
|
703
|
-
tree_search_nearest_forward(node, search_node) {
|
|
704
|
-
let best, curr = node;
|
|
705
|
-
for (; curr && curr !== this.nil_node; )
|
|
706
|
-
curr.less_than(search_node) ? curr.intersect(search_node) ? (best = curr, curr = curr.left) : curr = curr.right : ((!best || curr.less_than(best)) && (best = curr), curr = curr.left);
|
|
707
|
-
return best || null;
|
|
708
|
-
}
|
|
709
|
-
// Original search_interval method; container res support push() insertion
|
|
710
|
-
// Search all intervals intersecting given one
|
|
711
|
-
tree_search_interval(node, search_node, res) {
|
|
712
|
-
node != null && node !== this.nil_node && (node.left !== this.nil_node && !node.not_intersect_left_subtree(search_node) && this.tree_search_interval(node.left, search_node, res), node.intersect(search_node) && res.push(node), node.right !== this.nil_node && !node.not_intersect_right_subtree(search_node) && this.tree_search_interval(node.right, search_node, res));
|
|
713
|
-
}
|
|
714
|
-
tree_find_any_interval(node, search_node) {
|
|
715
|
-
let found = !1;
|
|
716
|
-
return node != null && node !== this.nil_node && (node.left !== this.nil_node && !node.not_intersect_left_subtree(search_node) && (found = this.tree_find_any_interval(node.left, search_node)), found || (found = node.intersect(search_node)), !found && node.right !== this.nil_node && !node.not_intersect_right_subtree(search_node) && (found = this.tree_find_any_interval(node.right, search_node))), found;
|
|
717
|
-
}
|
|
718
|
-
local_minimum(node) {
|
|
719
|
-
let node_min = node;
|
|
720
|
-
for (; node_min.left != null && node_min.left !== this.nil_node; )
|
|
721
|
-
node_min = node_min.left;
|
|
722
|
-
return node_min;
|
|
723
|
-
}
|
|
724
|
-
// not in use
|
|
725
|
-
local_maximum(node) {
|
|
726
|
-
let node_max = node;
|
|
727
|
-
for (; node_max.right != null && node_max.right !== this.nil_node; )
|
|
728
|
-
node_max = node_max.right;
|
|
729
|
-
return node_max;
|
|
730
|
-
}
|
|
731
|
-
tree_successor(node) {
|
|
732
|
-
let node_successor, current_node, parent_node;
|
|
733
|
-
if (node.right !== this.nil_node)
|
|
734
|
-
node_successor = this.local_minimum(node.right);
|
|
735
|
-
else {
|
|
736
|
-
for (current_node = node, parent_node = node.parent; parent_node != null && parent_node.right === current_node; )
|
|
737
|
-
current_node = parent_node, parent_node = parent_node.parent;
|
|
738
|
-
node_successor = parent_node;
|
|
739
|
-
}
|
|
740
|
-
return node_successor;
|
|
741
|
-
}
|
|
742
|
-
// | right-rotate(T,y) |
|
|
743
|
-
// y ---------------. x
|
|
744
|
-
// / \ / \
|
|
745
|
-
// x c left-rotate(T,x) a y
|
|
746
|
-
// / \ <--------------- / \
|
|
747
|
-
// a b b c
|
|
748
|
-
rotate_left(x) {
|
|
749
|
-
let y = x.right;
|
|
750
|
-
x.right = y.left, y.left !== this.nil_node && (y.left.parent = x), y.parent = x.parent, x === this.root ? this.root = y : x === x.parent.left ? x.parent.left = y : x.parent.right = y, y.left = x, x.parent = y, x != null && x !== this.nil_node && x.update_max(), y = x.parent, y != null && y !== this.nil_node && y.update_max();
|
|
751
|
-
}
|
|
752
|
-
rotate_right(y) {
|
|
753
|
-
let x = y.left;
|
|
754
|
-
y.left = x.right, x.right !== this.nil_node && (x.right.parent = y), x.parent = y.parent, y === this.root ? this.root = x : y === y.parent.left ? y.parent.left = x : y.parent.right = x, x.right = y, y.parent = x, y !== null && y !== this.nil_node && y.update_max(), x = y.parent, x != null && x !== this.nil_node && x.update_max();
|
|
755
|
-
}
|
|
756
|
-
tree_walk(node, action) {
|
|
757
|
-
node != null && node !== this.nil_node && (this.tree_walk(node.left, action), action(node), this.tree_walk(node.right, action));
|
|
758
|
-
}
|
|
759
|
-
/* Return true if all red nodes have exactly two black child nodes */
|
|
760
|
-
testRedBlackProperty() {
|
|
761
|
-
let res = !0;
|
|
762
|
-
return this.tree_walk(this.root, function(node) {
|
|
763
|
-
node.color === RB_TREE_COLOR_RED && (node.left.color === RB_TREE_COLOR_BLACK && node.right.color === RB_TREE_COLOR_BLACK || (res = !1));
|
|
764
|
-
}), res;
|
|
765
|
-
}
|
|
766
|
-
/* Throw error if not every path from root to bottom has same black height */
|
|
767
|
-
testBlackHeightProperty(node) {
|
|
768
|
-
let height = 0, heightLeft = 0, heightRight = 0;
|
|
769
|
-
if (node.color === RB_TREE_COLOR_BLACK && height++, node.left !== this.nil_node ? heightLeft = this.testBlackHeightProperty(node.left) : heightLeft = 1, node.right !== this.nil_node ? heightRight = this.testBlackHeightProperty(node.right) : heightRight = 1, heightLeft !== heightRight)
|
|
770
|
-
throw new Error("Red-black height property violated");
|
|
771
|
-
return height += heightLeft, height;
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
__name(_IntervalTree, "IntervalTree");
|
|
775
|
-
let IntervalTree = _IntervalTree;
|
|
776
|
-
const _RuleMatrix = class _RuleMatrix {
|
|
777
|
-
constructor(value, _unitId, _subUnitId, _univerInstanceService, _disableTree = !1) {
|
|
778
|
-
__publicField(this, "_map");
|
|
779
|
-
__publicField(this, "_tree", /* @__PURE__ */ new Map());
|
|
780
|
-
__publicField(this, "_dirty", !0);
|
|
781
|
-
__publicField(this, "_buildTree", /* @__PURE__ */ __name(() => {
|
|
782
|
-
if (!this._dirty || this._disableTree)
|
|
783
|
-
return;
|
|
784
|
-
const map = /* @__PURE__ */ new Map();
|
|
785
|
-
this._map.forEach((ranges, ruleId) => {
|
|
786
|
-
ranges.forEach((range) => {
|
|
787
|
-
for (let col = range.startColumn; col <= range.endColumn; col++) {
|
|
788
|
-
let items = map.get(col);
|
|
789
|
-
items || (items = [], map.set(col, items)), items.push({
|
|
790
|
-
startRow: range.startRow,
|
|
791
|
-
endRow: range.endRow,
|
|
792
|
-
ruleId
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
});
|
|
796
|
-
});
|
|
797
|
-
const treeMap = /* @__PURE__ */ new Map();
|
|
798
|
-
map.forEach((items, col) => {
|
|
799
|
-
const tree = new IntervalTree();
|
|
800
|
-
items.forEach((item) => {
|
|
801
|
-
tree.insert([item.startRow, item.endRow], item.ruleId);
|
|
802
|
-
}), treeMap.set(col, tree);
|
|
803
|
-
}), this._tree = treeMap, this._dirty = !1;
|
|
804
|
-
}, "_buildTree"));
|
|
805
|
-
__publicField(this, "_debonceBuildTree", debounce(this._buildTree, 0));
|
|
806
|
-
this._unitId = _unitId, this._subUnitId = _subUnitId, this._univerInstanceService = _univerInstanceService, this._disableTree = _disableTree, this._map = value, this._buildTree();
|
|
807
|
-
}
|
|
808
|
-
get _worksheet() {
|
|
809
|
-
var _a12;
|
|
810
|
-
return (_a12 = this._univerInstanceService.getUnit(this._unitId, UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a12.getSheetBySheetId(this._subUnitId);
|
|
811
|
-
}
|
|
812
|
-
addRule(rule) {
|
|
813
|
-
if (!this._worksheet)
|
|
814
|
-
return;
|
|
815
|
-
const ruleId = rule.uid, ranges = rule.ranges.map((range) => Range.transformRange(range, this._worksheet));
|
|
816
|
-
this._map.forEach((value, key) => {
|
|
817
|
-
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
818
|
-
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
819
|
-
}), this._dirty = !0, this._map.set(ruleId, ranges), this._debonceBuildTree();
|
|
820
|
-
}
|
|
821
|
-
removeRange(_ranges) {
|
|
822
|
-
if (!this._worksheet)
|
|
823
|
-
return;
|
|
824
|
-
const ranges = _ranges.map((range) => Range.transformRange(range, this._worksheet));
|
|
825
|
-
this._map.forEach((value, key) => {
|
|
826
|
-
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
827
|
-
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
828
|
-
}), this._dirty = !0, this._debonceBuildTree();
|
|
829
|
-
}
|
|
830
|
-
removeRule(rule) {
|
|
831
|
-
this._map.delete(rule.uid), this._dirty = !0, this._debonceBuildTree();
|
|
832
|
-
}
|
|
833
|
-
updateRange(ruleId, _newRanges) {
|
|
834
|
-
if (!this._worksheet)
|
|
835
|
-
return;
|
|
836
|
-
this._map.delete(ruleId);
|
|
837
|
-
const ranges = _newRanges.map((range) => Range.transformRange(range, this._worksheet));
|
|
838
|
-
this._map.forEach((value, key) => {
|
|
839
|
-
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
840
|
-
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
841
|
-
}), this._map.set(ruleId, ranges), this._dirty = !0, this._debonceBuildTree();
|
|
842
|
-
}
|
|
843
|
-
addRangeRules(rules) {
|
|
844
|
-
rules.forEach(({ id: ruleId, ranges }) => {
|
|
845
|
-
if (!ranges.length)
|
|
846
|
-
return;
|
|
847
|
-
let current = this._map.get(ruleId);
|
|
848
|
-
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) => {
|
|
849
|
-
if (key === ruleId)
|
|
850
|
-
return;
|
|
851
|
-
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
852
|
-
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
853
|
-
});
|
|
854
|
-
}), this._dirty = !0, this._debonceBuildTree();
|
|
855
|
-
}
|
|
856
|
-
diff(rules) {
|
|
857
|
-
const mutations = [];
|
|
858
|
-
let deleteIndex = 0;
|
|
859
|
-
return rules.forEach((rule, index) => {
|
|
860
|
-
var _a12;
|
|
861
|
-
const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [], oldRanges = rule.ranges;
|
|
862
|
-
newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) && mutations.push({
|
|
863
|
-
type: "update",
|
|
864
|
-
ruleId: rule.uid,
|
|
865
|
-
oldRanges,
|
|
866
|
-
newRanges
|
|
867
|
-
}), newRanges.length === 0 && (mutations.push({
|
|
868
|
-
type: "delete",
|
|
869
|
-
rule,
|
|
870
|
-
index: index - deleteIndex
|
|
871
|
-
}), deleteIndex++);
|
|
872
|
-
}), mutations;
|
|
873
|
-
}
|
|
874
|
-
diffWithAddition(rules, additionRules) {
|
|
875
|
-
const mutations = [];
|
|
876
|
-
let deleteIndex = 0;
|
|
877
|
-
return rules.forEach((rule, index) => {
|
|
878
|
-
var _a12;
|
|
879
|
-
const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [], oldRanges = rule.ranges;
|
|
880
|
-
newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) && mutations.push({
|
|
881
|
-
type: "update",
|
|
882
|
-
ruleId: rule.uid,
|
|
883
|
-
oldRanges,
|
|
884
|
-
newRanges
|
|
885
|
-
}), newRanges.length === 0 && (mutations.push({
|
|
886
|
-
type: "delete",
|
|
887
|
-
rule,
|
|
888
|
-
index: index - deleteIndex
|
|
889
|
-
}), deleteIndex++);
|
|
890
|
-
}), Array.from(additionRules).forEach((rule) => {
|
|
891
|
-
var _a12;
|
|
892
|
-
const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [];
|
|
893
|
-
mutations.push({
|
|
894
|
-
type: "add",
|
|
895
|
-
rule: {
|
|
896
|
-
...rule,
|
|
897
|
-
ranges: newRanges
|
|
898
|
-
}
|
|
899
|
-
});
|
|
900
|
-
}), mutations;
|
|
901
|
-
}
|
|
902
|
-
clone() {
|
|
903
|
-
return new _RuleMatrix(
|
|
904
|
-
new Map(Tools.deepClone(Array.from(this._map.entries()))),
|
|
905
|
-
this._unitId,
|
|
906
|
-
this._subUnitId,
|
|
907
|
-
this._univerInstanceService,
|
|
908
|
-
// disable tree on cloned matrix, cause there is no need to search
|
|
909
|
-
!0
|
|
910
|
-
);
|
|
911
|
-
}
|
|
912
|
-
getValue(row, col) {
|
|
913
|
-
this._dirty && this._buildTree();
|
|
914
|
-
const tree = this._tree.get(col);
|
|
915
|
-
if (!tree)
|
|
916
|
-
return;
|
|
917
|
-
const result = tree.search([row, row]);
|
|
918
|
-
return result.length > 0 ? result[0] : void 0;
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
__name(_RuleMatrix, "RuleMatrix");
|
|
922
|
-
let RuleMatrix = _RuleMatrix;
|
|
923
|
-
var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
924
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
925
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
926
|
-
return kind && result && __defProp$6(target, key, result), result;
|
|
927
|
-
}, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a5;
|
|
928
|
-
let SheetDataValidationModel = (_a5 = class extends Disposable {
|
|
929
|
-
constructor(_dataValidationModel, _univerInstanceService, _dataValidatorRegistryService, _dataValidationCacheService, _dataValidationFormulaService, _dataValidationCustomFormulaService, _commandService) {
|
|
930
|
-
super();
|
|
931
|
-
__publicField(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
|
|
932
|
-
__publicField(this, "_validStatusChange$", new Subject());
|
|
933
|
-
__publicField(this, "_ruleChange$", new Subject());
|
|
934
|
-
__publicField(this, "ruleChange$", this._ruleChange$.asObservable());
|
|
935
|
-
__publicField(this, "validStatusChange$", this._validStatusChange$.asObservable());
|
|
936
|
-
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(() => {
|
|
937
|
-
this._ruleChange$.complete(), this._validStatusChange$.complete();
|
|
938
|
-
}), this._initUniverInstanceListener();
|
|
939
|
-
}
|
|
940
|
-
_initUniverInstanceListener() {
|
|
941
|
-
this.disposeWithMe(
|
|
942
|
-
this._univerInstanceService.unitDisposed$.subscribe((unit) => {
|
|
943
|
-
this._ruleMatrixMap.delete(unit.getUnitId());
|
|
944
|
-
})
|
|
945
|
-
), this.disposeWithMe(
|
|
946
|
-
this._commandService.onCommandExecuted((command) => {
|
|
947
|
-
if (command.id === RemoveSheetMutation.id) {
|
|
948
|
-
const { unitId, subUnitId } = command.params, subUnitMap = this._ruleMatrixMap.get(unitId);
|
|
949
|
-
subUnitMap && subUnitMap.delete(subUnitId);
|
|
950
|
-
}
|
|
951
|
-
})
|
|
952
|
-
);
|
|
953
|
-
}
|
|
954
|
-
_initRuleUpdateListener() {
|
|
955
|
-
const allRules = this._dataValidationModel.getAll();
|
|
956
|
-
for (const [unitId, subUnitMap] of allRules)
|
|
957
|
-
for (const [subUnitId, rules] of subUnitMap)
|
|
958
|
-
for (const rule of rules)
|
|
959
|
-
this._ruleChange$.next({
|
|
960
|
-
type: "add",
|
|
961
|
-
unitId,
|
|
962
|
-
subUnitId,
|
|
963
|
-
rule,
|
|
964
|
-
source: "patched"
|
|
965
|
-
}), this._addRule(unitId, subUnitId, rule);
|
|
966
|
-
this.disposeWithMe(
|
|
967
|
-
this._dataValidationModel.ruleChange$.subscribe((ruleChange) => {
|
|
968
|
-
switch (this._ruleChange$.next(ruleChange), ruleChange.type) {
|
|
969
|
-
case "add":
|
|
970
|
-
this._addRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
971
|
-
break;
|
|
972
|
-
case "update":
|
|
973
|
-
this._updateRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule.uid, ruleChange.oldRule, ruleChange.updatePayload);
|
|
974
|
-
break;
|
|
975
|
-
case "remove":
|
|
976
|
-
this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
977
|
-
break;
|
|
978
|
-
}
|
|
979
|
-
})
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
_ensureRuleMatrix(unitId, subUnitId) {
|
|
983
|
-
let unitMap = this._ruleMatrixMap.get(unitId);
|
|
984
|
-
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._ruleMatrixMap.set(unitId, unitMap));
|
|
985
|
-
let matrix = unitMap.get(subUnitId);
|
|
986
|
-
return matrix || (matrix = new RuleMatrix(/* @__PURE__ */ new Map(), unitId, subUnitId, this._univerInstanceService), unitMap.set(subUnitId, matrix)), matrix;
|
|
987
|
-
}
|
|
988
|
-
_addRuleSideEffect(unitId, subUnitId, rule) {
|
|
989
|
-
this._ensureRuleMatrix(unitId, subUnitId).addRule(rule), this._dataValidationCacheService.addRule(unitId, subUnitId, rule), this._dataValidationFormulaService.addRule(unitId, subUnitId, rule.uid, rule.formula1, rule.formula2), rule.type === DataValidationType.CUSTOM && this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, rule);
|
|
990
|
-
}
|
|
991
|
-
_addRule(unitId, subUnitId, rule) {
|
|
992
|
-
(Array.isArray(rule) ? rule : [rule]).forEach((item) => {
|
|
993
|
-
this._addRuleSideEffect(unitId, subUnitId, item);
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
_updateRule(unitId, subUnitId, ruleId, oldRule, payload) {
|
|
997
|
-
const ruleMatrix = this._ensureRuleMatrix(unitId, subUnitId);
|
|
998
|
-
payload.type === UpdateRuleType.RANGE ? (ruleMatrix.updateRange(ruleId, payload.payload), this._dataValidationCacheService.updateRuleRanges(unitId, subUnitId, ruleId, payload.payload, oldRule.ranges), oldRule.type === DataValidationType.CUSTOM && this._dataValidationCustomFormulaService.updateRuleRanges(unitId, subUnitId, ruleId, oldRule.ranges, payload.payload)) : payload.type === UpdateRuleType.SETTING && (this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, oldRule.ranges), this._dataValidationFormulaService.updateRuleFormulaText(unitId, subUnitId, ruleId, payload.payload.formula1, payload.payload.formula2), oldRule.type === DataValidationType.CUSTOM ? this._dataValidationCustomFormulaService.updateRuleFormula(unitId, subUnitId, ruleId, oldRule.ranges, payload.payload.formula1) : payload.payload.type === DataValidationType.CUSTOM && this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, {
|
|
999
|
-
...oldRule,
|
|
1000
|
-
...payload.payload
|
|
1001
|
-
}));
|
|
1002
|
-
}
|
|
1003
|
-
_removeRule(unitId, subUnitId, oldRule) {
|
|
1004
|
-
this._ensureRuleMatrix(unitId, subUnitId).removeRule(oldRule), this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule), oldRule.type === DataValidationType.CUSTOM && this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, oldRule.uid);
|
|
1005
|
-
}
|
|
1006
|
-
getValidator(type) {
|
|
1007
|
-
return this._dataValidatorRegistryService.getValidatorItem(type);
|
|
1008
|
-
}
|
|
1009
|
-
getRuleIdByLocation(unitId, subUnitId, row, col) {
|
|
1010
|
-
return this._ensureRuleMatrix(unitId, subUnitId).getValue(row, col);
|
|
1011
|
-
}
|
|
1012
|
-
getRuleByLocation(unitId, subUnitId, row, col) {
|
|
1013
|
-
const ruleId = this.getRuleIdByLocation(unitId, subUnitId, row, col);
|
|
1014
|
-
if (ruleId)
|
|
1015
|
-
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1016
|
-
}
|
|
1017
|
-
validator(rule, pos, _onCompete) {
|
|
1018
|
-
const { col, row, unitId, subUnitId, worksheet } = pos, ruleId = rule.uid, formula1 = rule.formula1, formula2 = rule.formula2, onCompete = /* @__PURE__ */ __name((status, changed) => {
|
|
1019
|
-
_onCompete && _onCompete(status, changed), changed && this._validStatusChange$.next({
|
|
1020
|
-
unitId,
|
|
1021
|
-
subUnitId,
|
|
1022
|
-
ruleId: rule.uid,
|
|
1023
|
-
status,
|
|
1024
|
-
row,
|
|
1025
|
-
col
|
|
1026
|
-
});
|
|
1027
|
-
}, "onCompete"), cell = worksheet.getCellValueOnly(row, col), validator = this.getValidator(rule.type), cellRaw = worksheet.getCellRaw(row, col), cellValue = getCellValueOrigin(cellRaw), interceptValue = getCellValueOrigin(cell);
|
|
1028
|
-
if (validator) {
|
|
1029
|
-
const cache = this._dataValidationCacheService.ensureCache(unitId, subUnitId), current = cache.getValue(row, col);
|
|
1030
|
-
return !current || current.value !== cellValue || current.interceptValue !== interceptValue || current.ruleId !== ruleId || current.formula1 !== formula1 || current.formula2 !== formula2 ? (cache.setValue(row, col, {
|
|
1031
|
-
value: cellValue,
|
|
1032
|
-
interceptValue,
|
|
1033
|
-
status: DataValidationStatus.VALIDATING,
|
|
1034
|
-
ruleId,
|
|
1035
|
-
formula1: formula1 || "",
|
|
1036
|
-
formula2: formula2 || ""
|
|
1037
|
-
}), validator.validator(
|
|
1038
|
-
{
|
|
1039
|
-
value: cellValue,
|
|
1040
|
-
unitId,
|
|
1041
|
-
subUnitId,
|
|
1042
|
-
row,
|
|
1043
|
-
column: col,
|
|
1044
|
-
worksheet: pos.worksheet,
|
|
1045
|
-
workbook: pos.workbook,
|
|
1046
|
-
interceptValue: getCellValueOrigin(cell),
|
|
1047
|
-
t: cellRaw == null ? void 0 : cellRaw.t
|
|
1048
|
-
},
|
|
1049
|
-
rule
|
|
1050
|
-
).then((status) => {
|
|
1051
|
-
const realStatus = status ? DataValidationStatus.VALID : DataValidationStatus.INVALID;
|
|
1052
|
-
cache.setValue(row, col, {
|
|
1053
|
-
value: cellValue,
|
|
1054
|
-
status: realStatus,
|
|
1055
|
-
ruleId,
|
|
1056
|
-
interceptValue,
|
|
1057
|
-
formula1: formula1 || "",
|
|
1058
|
-
formula2: formula2 || ""
|
|
1059
|
-
}), onCompete(realStatus, !0);
|
|
1060
|
-
}), DataValidationStatus.VALIDATING) : (onCompete(current.status, !1), current.status);
|
|
1061
|
-
} else
|
|
1062
|
-
return onCompete(DataValidationStatus.VALID, !1), DataValidationStatus.VALID;
|
|
1063
|
-
}
|
|
1064
|
-
getRuleErrorMsg(unitId, subUnitId, ruleId) {
|
|
1065
|
-
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1066
|
-
if (!rule)
|
|
1067
|
-
return "";
|
|
1068
|
-
const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
|
|
1069
|
-
return rule.error ? rule.error : validator ? validator.getRuleFinalError(rule) : "";
|
|
1070
|
-
}
|
|
1071
|
-
getRuleObjectMatrix(unitId, subUnitId) {
|
|
1072
|
-
return this._ensureRuleMatrix(unitId, subUnitId);
|
|
1073
|
-
}
|
|
1074
|
-
getRuleById(unitId, subUnitId, ruleId) {
|
|
1075
|
-
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1076
|
-
}
|
|
1077
|
-
getRuleIndex(unitId, subUnitId, ruleId) {
|
|
1078
|
-
return this._dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId);
|
|
1079
|
-
}
|
|
1080
|
-
getRules(unitId, subUnitId) {
|
|
1081
|
-
return [...this._dataValidationModel.getRules(unitId, subUnitId)];
|
|
1082
|
-
}
|
|
1083
|
-
getUnitRules(unitId) {
|
|
1084
|
-
return this._dataValidationModel.getUnitRules(unitId);
|
|
1085
|
-
}
|
|
1086
|
-
deleteUnitRules(unitId) {
|
|
1087
|
-
return this._dataValidationModel.deleteUnitRules(unitId);
|
|
1088
|
-
}
|
|
1089
|
-
getSubUnitIds(unitId) {
|
|
1090
|
-
return this._dataValidationModel.getSubUnitIds(unitId);
|
|
1091
|
-
}
|
|
1092
|
-
getAll() {
|
|
1093
|
-
return this._dataValidationModel.getAll();
|
|
1094
|
-
}
|
|
1095
|
-
}, __name(_a5, "SheetDataValidationModel"), _a5);
|
|
1096
|
-
SheetDataValidationModel = __decorateClass$6([
|
|
1097
|
-
__decorateParam$6(0, Inject(DataValidationModel)),
|
|
1098
|
-
__decorateParam$6(1, IUniverInstanceService),
|
|
1099
|
-
__decorateParam$6(2, Inject(DataValidatorRegistryService)),
|
|
1100
|
-
__decorateParam$6(3, Inject(DataValidationCacheService)),
|
|
1101
|
-
__decorateParam$6(4, Inject(DataValidationFormulaService)),
|
|
1102
|
-
__decorateParam$6(5, Inject(DataValidationCustomFormulaService)),
|
|
1103
|
-
__decorateParam$6(6, ICommandService)
|
|
1104
|
-
], SheetDataValidationModel);
|
|
1105
|
-
function getFormulaResult(result) {
|
|
1106
|
-
var _a12, _b;
|
|
1107
|
-
return (_b = (_a12 = result == null ? void 0 : result[0]) == null ? void 0 : _a12[0]) == null ? void 0 : _b.v;
|
|
1108
|
-
}
|
|
1109
|
-
__name(getFormulaResult, "getFormulaResult");
|
|
1110
|
-
function getFormulaCellData(result) {
|
|
1111
|
-
var _a12;
|
|
1112
|
-
return (_a12 = result == null ? void 0 : result[0]) == null ? void 0 : _a12[0];
|
|
1113
|
-
}
|
|
1114
|
-
__name(getFormulaCellData, "getFormulaCellData");
|
|
1115
|
-
const CHECKBOX_FORMULA_1 = 1, CHECKBOX_FORMULA_2 = 0;
|
|
1116
|
-
function getFailMessage(formula, localeService) {
|
|
1117
|
-
return Tools.isBlank(formula) ? localeService.t("dataValidation.validFail.value") : isFormulaString(formula) ? localeService.t("dataValidation.validFail.primitive") : "";
|
|
1118
|
-
}
|
|
1119
|
-
__name(getFailMessage, "getFailMessage");
|
|
1120
|
-
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 {
|
|
1121
|
-
constructor() {
|
|
1122
|
-
super(...arguments);
|
|
1123
|
-
__publicField(this, "id", DataValidationType.CHECKBOX);
|
|
1124
|
-
__publicField(this, "title", "dataValidation.checkbox.title");
|
|
1125
|
-
__publicField(this, "operators", []);
|
|
1126
|
-
__publicField(this, "scopes", ["sheet"]);
|
|
1127
|
-
__publicField(this, "_formulaService", this.injector.get(DataValidationFormulaService));
|
|
1128
|
-
__publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name((rule, cellValue, pos) => {
|
|
1129
|
-
const { formula1, formula2 } = this.parseFormulaSync(rule, pos.unitId, pos.subUnitId), valueStr = `${cellValue != null ? cellValue : ""}`;
|
|
1130
|
-
return !valueStr || valueStr === `${formula1}` || valueStr === `${formula2}`;
|
|
1131
|
-
}, "skipDefaultFontRender"));
|
|
1132
|
-
}
|
|
1133
|
-
validatorFormula(rule, unitId, subUnitId) {
|
|
1134
|
-
const { formula1, formula2 } = rule, isEqual = formula1 === formula2;
|
|
1135
|
-
if (Tools.isBlank(formula1) && Tools.isBlank(formula2))
|
|
1136
|
-
return {
|
|
1137
|
-
success: !0
|
|
1138
|
-
};
|
|
1139
|
-
if (isEqual)
|
|
1140
|
-
return {
|
|
1141
|
-
success: !1,
|
|
1142
|
-
formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
|
|
1143
|
-
formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
|
|
1144
|
-
};
|
|
1145
|
-
const error1 = getFailMessage(formula1, this.localeService), error2 = getFailMessage(formula2, this.localeService);
|
|
1146
|
-
return {
|
|
1147
|
-
success: !error1 && !error2,
|
|
1148
|
-
formula1: error1,
|
|
1149
|
-
formula2: error2
|
|
1150
|
-
};
|
|
1151
|
-
}
|
|
1152
|
-
async parseFormula(rule, unitId, subUnitId) {
|
|
1153
|
-
var _a12, _b;
|
|
1154
|
-
const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2;
|
|
1155
|
-
return {
|
|
1156
|
-
formula1: transformCheckboxValue(originFormula1),
|
|
1157
|
-
formula2: transformCheckboxValue(originFormula2),
|
|
1158
|
-
originFormula1,
|
|
1159
|
-
originFormula2
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
|
-
getExtraStyle(rule, value) {
|
|
1163
|
-
return {
|
|
1164
|
-
tb: WrapStrategy.CLIP
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
parseFormulaSync(rule, unitId, subUnitId) {
|
|
1168
|
-
var _a12, _b;
|
|
1169
|
-
const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2;
|
|
1170
|
-
return {
|
|
1171
|
-
formula1: transformCheckboxValue(originFormula1),
|
|
1172
|
-
formula2: transformCheckboxValue(originFormula2),
|
|
1173
|
-
originFormula1,
|
|
1174
|
-
originFormula2
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
async isValidType(cellInfo, formula, rule) {
|
|
1178
|
-
const { value, unitId, subUnitId } = cellInfo, { formula1, formula2, originFormula1, originFormula2 } = await this.parseFormula(rule, unitId, subUnitId);
|
|
1179
|
-
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 : ""));
|
|
1180
|
-
}
|
|
1181
|
-
generateRuleErrorMessage(rule) {
|
|
1182
|
-
return this.localeService.t("dataValidation.checkbox.error");
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
__name(_CheckboxValidator, "CheckboxValidator");
|
|
1186
|
-
let CheckboxValidator = _CheckboxValidator;
|
|
1187
|
-
var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
1188
|
-
function getDefaultExportFromCjs(x) {
|
|
1189
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
|
|
1190
|
-
}
|
|
1191
|
-
__name(getDefaultExportFromCjs, "getDefaultExportFromCjs");
|
|
1192
|
-
var dayjs_min = { exports: {} };
|
|
1193
|
-
(function(module, exports) {
|
|
1194
|
-
(function(t, e) {
|
|
1195
|
-
module.exports = e();
|
|
1196
|
-
})(commonjsGlobal, function() {
|
|
1197
|
-
var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: /* @__PURE__ */ __name(function(t2) {
|
|
1198
|
-
var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
|
|
1199
|
-
return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
|
|
1200
|
-
}, "ordinal") }, m = /* @__PURE__ */ __name(function(t2, e2, n2) {
|
|
1201
|
-
var r2 = String(t2);
|
|
1202
|
-
return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
|
|
1203
|
-
}, "m"), v = { s: m, z: /* @__PURE__ */ __name(function(t2) {
|
|
1204
|
-
var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
|
|
1205
|
-
return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
|
|
1206
|
-
}, "z"), m: /* @__PURE__ */ __name(function t2(e2, n2) {
|
|
1207
|
-
if (e2.date() < n2.date()) return -t2(n2, e2);
|
|
1208
|
-
var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
|
|
1209
|
-
return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
|
|
1210
|
-
}, "t"), a: /* @__PURE__ */ __name(function(t2) {
|
|
1211
|
-
return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
|
|
1212
|
-
}, "a"), p: /* @__PURE__ */ __name(function(t2) {
|
|
1213
|
-
return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
|
|
1214
|
-
}, "p"), u: /* @__PURE__ */ __name(function(t2) {
|
|
1215
|
-
return t2 === void 0;
|
|
1216
|
-
}, "u") }, g = "en", D2 = {};
|
|
1217
|
-
D2[g] = M;
|
|
1218
|
-
var p = "$isDayjsObject", S = /* @__PURE__ */ __name(function(t2) {
|
|
1219
|
-
return t2 instanceof _ || !(!t2 || !t2[p]);
|
|
1220
|
-
}, "S"), w = /* @__PURE__ */ __name(function t2(e2, n2, r2) {
|
|
1221
|
-
var i2;
|
|
1222
|
-
if (!e2) return g;
|
|
1223
|
-
if (typeof e2 == "string") {
|
|
1224
|
-
var s2 = e2.toLowerCase();
|
|
1225
|
-
D2[s2] && (i2 = s2), n2 && (D2[s2] = n2, i2 = s2);
|
|
1226
|
-
var u2 = e2.split("-");
|
|
1227
|
-
if (!i2 && u2.length > 1) return t2(u2[0]);
|
|
1228
|
-
} else {
|
|
1229
|
-
var a2 = e2.name;
|
|
1230
|
-
D2[a2] = e2, i2 = a2;
|
|
1231
|
-
}
|
|
1232
|
-
return !r2 && i2 && (g = i2), i2 || !r2 && g;
|
|
1233
|
-
}, "t"), O = /* @__PURE__ */ __name(function(t2, e2) {
|
|
1234
|
-
if (S(t2)) return t2.clone();
|
|
1235
|
-
var n2 = typeof e2 == "object" ? e2 : {};
|
|
1236
|
-
return n2.date = t2, n2.args = arguments, new _(n2);
|
|
1237
|
-
}, "O"), b = v;
|
|
1238
|
-
b.l = w, b.i = S, b.w = function(t2, e2) {
|
|
1239
|
-
return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
|
|
1240
|
-
};
|
|
1241
|
-
var _ = function() {
|
|
1242
|
-
function M2(t2) {
|
|
1243
|
-
this.$L = w(t2.locale, null, !0), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = !0;
|
|
1244
|
-
}
|
|
1245
|
-
__name(M2, "M");
|
|
1246
|
-
var m2 = M2.prototype;
|
|
1247
|
-
return m2.parse = function(t2) {
|
|
1248
|
-
this.$d = function(t3) {
|
|
1249
|
-
var e2 = t3.date, n2 = t3.utc;
|
|
1250
|
-
if (e2 === null) return /* @__PURE__ */ new Date(NaN);
|
|
1251
|
-
if (b.u(e2)) return /* @__PURE__ */ new Date();
|
|
1252
|
-
if (e2 instanceof Date) return new Date(e2);
|
|
1253
|
-
if (typeof e2 == "string" && !/Z$/i.test(e2)) {
|
|
1254
|
-
var r2 = e2.match($);
|
|
1255
|
-
if (r2) {
|
|
1256
|
-
var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
|
|
1257
|
-
return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
return new Date(e2);
|
|
1261
|
-
}(t2), this.init();
|
|
1262
|
-
}, m2.init = function() {
|
|
1263
|
-
var t2 = this.$d;
|
|
1264
|
-
this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
|
|
1265
|
-
}, m2.$utils = function() {
|
|
1266
|
-
return b;
|
|
1267
|
-
}, m2.isValid = function() {
|
|
1268
|
-
return this.$d.toString() !== l;
|
|
1269
|
-
}, m2.isSame = function(t2, e2) {
|
|
1270
|
-
var n2 = O(t2);
|
|
1271
|
-
return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
|
|
1272
|
-
}, m2.isAfter = function(t2, e2) {
|
|
1273
|
-
return O(t2) < this.startOf(e2);
|
|
1274
|
-
}, m2.isBefore = function(t2, e2) {
|
|
1275
|
-
return this.endOf(e2) < O(t2);
|
|
1276
|
-
}, m2.$g = function(t2, e2, n2) {
|
|
1277
|
-
return b.u(t2) ? this[e2] : this.set(n2, t2);
|
|
1278
|
-
}, m2.unix = function() {
|
|
1279
|
-
return Math.floor(this.valueOf() / 1e3);
|
|
1280
|
-
}, m2.valueOf = function() {
|
|
1281
|
-
return this.$d.getTime();
|
|
1282
|
-
}, m2.startOf = function(t2, e2) {
|
|
1283
|
-
var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = /* @__PURE__ */ __name(function(t3, e3) {
|
|
1284
|
-
var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
|
|
1285
|
-
return r2 ? i2 : i2.endOf(a);
|
|
1286
|
-
}, "l"), $2 = /* @__PURE__ */ __name(function(t3, e3) {
|
|
1287
|
-
return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
|
|
1288
|
-
}, "$"), y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
|
|
1289
|
-
switch (f2) {
|
|
1290
|
-
case h:
|
|
1291
|
-
return r2 ? l2(1, 0) : l2(31, 11);
|
|
1292
|
-
case c:
|
|
1293
|
-
return r2 ? l2(1, M3) : l2(0, M3 + 1);
|
|
1294
|
-
case o:
|
|
1295
|
-
var g2 = this.$locale().weekStart || 0, D3 = (y2 < g2 ? y2 + 7 : y2) - g2;
|
|
1296
|
-
return l2(r2 ? m3 - D3 : m3 + (6 - D3), M3);
|
|
1297
|
-
case a:
|
|
1298
|
-
case d:
|
|
1299
|
-
return $2(v2 + "Hours", 0);
|
|
1300
|
-
case u:
|
|
1301
|
-
return $2(v2 + "Minutes", 1);
|
|
1302
|
-
case s:
|
|
1303
|
-
return $2(v2 + "Seconds", 2);
|
|
1304
|
-
case i:
|
|
1305
|
-
return $2(v2 + "Milliseconds", 3);
|
|
1306
|
-
default:
|
|
1307
|
-
return this.clone();
|
|
1308
|
-
}
|
|
1309
|
-
}, m2.endOf = function(t2) {
|
|
1310
|
-
return this.startOf(t2, !1);
|
|
1311
|
-
}, m2.$set = function(t2, e2) {
|
|
1312
|
-
var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
|
|
1313
|
-
if (o2 === c || o2 === h) {
|
|
1314
|
-
var y2 = this.clone().set(d, 1);
|
|
1315
|
-
y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
|
|
1316
|
-
} else l2 && this.$d[l2]($2);
|
|
1317
|
-
return this.init(), this;
|
|
1318
|
-
}, m2.set = function(t2, e2) {
|
|
1319
|
-
return this.clone().$set(t2, e2);
|
|
1320
|
-
}, m2.get = function(t2) {
|
|
1321
|
-
return this[b.p(t2)]();
|
|
1322
|
-
}, m2.add = function(r2, f2) {
|
|
1323
|
-
var d2, l2 = this;
|
|
1324
|
-
r2 = Number(r2);
|
|
1325
|
-
var $2 = b.p(f2), y2 = /* @__PURE__ */ __name(function(t2) {
|
|
1326
|
-
var e2 = O(l2);
|
|
1327
|
-
return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
|
|
1328
|
-
}, "y");
|
|
1329
|
-
if ($2 === c) return this.set(c, this.$M + r2);
|
|
1330
|
-
if ($2 === h) return this.set(h, this.$y + r2);
|
|
1331
|
-
if ($2 === a) return y2(1);
|
|
1332
|
-
if ($2 === o) return y2(7);
|
|
1333
|
-
var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
|
|
1334
|
-
return b.w(m3, this);
|
|
1335
|
-
}, m2.subtract = function(t2, e2) {
|
|
1336
|
-
return this.add(-1 * t2, e2);
|
|
1337
|
-
}, m2.format = function(t2) {
|
|
1338
|
-
var e2 = this, n2 = this.$locale();
|
|
1339
|
-
if (!this.isValid()) return n2.invalidDate || l;
|
|
1340
|
-
var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = /* @__PURE__ */ __name(function(t3, n3, i3, s3) {
|
|
1341
|
-
return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
|
|
1342
|
-
}, "h"), d2 = /* @__PURE__ */ __name(function(t3) {
|
|
1343
|
-
return b.s(s2 % 12 || 12, t3, "0");
|
|
1344
|
-
}, "d"), $2 = f2 || function(t3, e3, n3) {
|
|
1345
|
-
var r3 = t3 < 12 ? "AM" : "PM";
|
|
1346
|
-
return n3 ? r3.toLowerCase() : r3;
|
|
1347
|
-
};
|
|
1348
|
-
return r2.replace(y, function(t3, r3) {
|
|
1349
|
-
return r3 || function(t4) {
|
|
1350
|
-
switch (t4) {
|
|
1351
|
-
case "YY":
|
|
1352
|
-
return String(e2.$y).slice(-2);
|
|
1353
|
-
case "YYYY":
|
|
1354
|
-
return b.s(e2.$y, 4, "0");
|
|
1355
|
-
case "M":
|
|
1356
|
-
return a2 + 1;
|
|
1357
|
-
case "MM":
|
|
1358
|
-
return b.s(a2 + 1, 2, "0");
|
|
1359
|
-
case "MMM":
|
|
1360
|
-
return h2(n2.monthsShort, a2, c2, 3);
|
|
1361
|
-
case "MMMM":
|
|
1362
|
-
return h2(c2, a2);
|
|
1363
|
-
case "D":
|
|
1364
|
-
return e2.$D;
|
|
1365
|
-
case "DD":
|
|
1366
|
-
return b.s(e2.$D, 2, "0");
|
|
1367
|
-
case "d":
|
|
1368
|
-
return String(e2.$W);
|
|
1369
|
-
case "dd":
|
|
1370
|
-
return h2(n2.weekdaysMin, e2.$W, o2, 2);
|
|
1371
|
-
case "ddd":
|
|
1372
|
-
return h2(n2.weekdaysShort, e2.$W, o2, 3);
|
|
1373
|
-
case "dddd":
|
|
1374
|
-
return o2[e2.$W];
|
|
1375
|
-
case "H":
|
|
1376
|
-
return String(s2);
|
|
1377
|
-
case "HH":
|
|
1378
|
-
return b.s(s2, 2, "0");
|
|
1379
|
-
case "h":
|
|
1380
|
-
return d2(1);
|
|
1381
|
-
case "hh":
|
|
1382
|
-
return d2(2);
|
|
1383
|
-
case "a":
|
|
1384
|
-
return $2(s2, u2, !0);
|
|
1385
|
-
case "A":
|
|
1386
|
-
return $2(s2, u2, !1);
|
|
1387
|
-
case "m":
|
|
1388
|
-
return String(u2);
|
|
1389
|
-
case "mm":
|
|
1390
|
-
return b.s(u2, 2, "0");
|
|
1391
|
-
case "s":
|
|
1392
|
-
return String(e2.$s);
|
|
1393
|
-
case "ss":
|
|
1394
|
-
return b.s(e2.$s, 2, "0");
|
|
1395
|
-
case "SSS":
|
|
1396
|
-
return b.s(e2.$ms, 3, "0");
|
|
1397
|
-
case "Z":
|
|
1398
|
-
return i2;
|
|
1399
|
-
}
|
|
1400
|
-
return null;
|
|
1401
|
-
}(t3) || i2.replace(":", "");
|
|
1402
|
-
});
|
|
1403
|
-
}, m2.utcOffset = function() {
|
|
1404
|
-
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
1405
|
-
}, m2.diff = function(r2, d2, l2) {
|
|
1406
|
-
var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D3 = /* @__PURE__ */ __name(function() {
|
|
1407
|
-
return b.m(y2, m3);
|
|
1408
|
-
}, "D");
|
|
1409
|
-
switch (M3) {
|
|
1410
|
-
case h:
|
|
1411
|
-
$2 = D3() / 12;
|
|
1412
|
-
break;
|
|
1413
|
-
case c:
|
|
1414
|
-
$2 = D3();
|
|
1415
|
-
break;
|
|
1416
|
-
case f:
|
|
1417
|
-
$2 = D3() / 3;
|
|
1418
|
-
break;
|
|
1419
|
-
case o:
|
|
1420
|
-
$2 = (g2 - v2) / 6048e5;
|
|
1421
|
-
break;
|
|
1422
|
-
case a:
|
|
1423
|
-
$2 = (g2 - v2) / 864e5;
|
|
1424
|
-
break;
|
|
1425
|
-
case u:
|
|
1426
|
-
$2 = g2 / n;
|
|
1427
|
-
break;
|
|
1428
|
-
case s:
|
|
1429
|
-
$2 = g2 / e;
|
|
1430
|
-
break;
|
|
1431
|
-
case i:
|
|
1432
|
-
$2 = g2 / t;
|
|
1433
|
-
break;
|
|
1434
|
-
default:
|
|
1435
|
-
$2 = g2;
|
|
1436
|
-
}
|
|
1437
|
-
return l2 ? $2 : b.a($2);
|
|
1438
|
-
}, m2.daysInMonth = function() {
|
|
1439
|
-
return this.endOf(c).$D;
|
|
1440
|
-
}, m2.$locale = function() {
|
|
1441
|
-
return D2[this.$L];
|
|
1442
|
-
}, m2.locale = function(t2, e2) {
|
|
1443
|
-
if (!t2) return this.$L;
|
|
1444
|
-
var n2 = this.clone(), r2 = w(t2, e2, !0);
|
|
1445
|
-
return r2 && (n2.$L = r2), n2;
|
|
1446
|
-
}, m2.clone = function() {
|
|
1447
|
-
return b.w(this.$d, this);
|
|
1448
|
-
}, m2.toDate = function() {
|
|
1449
|
-
return new Date(this.valueOf());
|
|
1450
|
-
}, m2.toJSON = function() {
|
|
1451
|
-
return this.isValid() ? this.toISOString() : null;
|
|
1452
|
-
}, m2.toISOString = function() {
|
|
1453
|
-
return this.$d.toISOString();
|
|
1454
|
-
}, m2.toString = function() {
|
|
1455
|
-
return this.$d.toUTCString();
|
|
1456
|
-
}, M2;
|
|
1457
|
-
}(), k = _.prototype;
|
|
1458
|
-
return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
|
|
1459
|
-
k[t2[1]] = function(e2) {
|
|
1460
|
-
return this.$g(e2, t2[0], t2[1]);
|
|
1461
|
-
};
|
|
1462
|
-
}), O.extend = function(t2, e2) {
|
|
1463
|
-
return t2.$i || (t2(e2, _, O), t2.$i = !0), O;
|
|
1464
|
-
}, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
|
|
1465
|
-
return O(1e3 * t2);
|
|
1466
|
-
}, O.en = D2[g], O.Ls = D2, O.p = {}, O;
|
|
1467
|
-
});
|
|
1468
|
-
})(dayjs_min);
|
|
1469
|
-
var dayjs_minExports = dayjs_min.exports;
|
|
1470
|
-
const dayjs = /* @__PURE__ */ getDefaultExportFromCjs(dayjs_minExports), DateOperatorNameMap = {
|
|
1471
|
-
[DataValidationOperator.BETWEEN]: "dataValidation.date.operators.between",
|
|
1472
|
-
[DataValidationOperator.EQUAL]: "dataValidation.date.operators.equal",
|
|
1473
|
-
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
|
|
1474
|
-
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
|
|
1475
|
-
[DataValidationOperator.LESS_THAN]: "dataValidation.date.operators.lessThan",
|
|
1476
|
-
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
|
|
1477
|
-
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
|
|
1478
|
-
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
|
|
1479
|
-
};
|
|
1480
|
-
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 + "";
|
|
1481
|
-
const DateOperatorTitleMap = {
|
|
1482
|
-
[DataValidationOperator.BETWEEN]: "dataValidation.date.ruleName.between",
|
|
1483
|
-
[DataValidationOperator.EQUAL]: "dataValidation.date.ruleName.equal",
|
|
1484
|
-
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
|
|
1485
|
-
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
|
|
1486
|
-
[DataValidationOperator.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
|
|
1487
|
-
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
|
|
1488
|
-
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
|
|
1489
|
-
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
|
|
1490
|
-
}, DateOperatorErrorTitleMap = {
|
|
1491
|
-
[DataValidationOperator.BETWEEN]: "dataValidation.date.errorMsg.between",
|
|
1492
|
-
[DataValidationOperator.EQUAL]: "dataValidation.date.errorMsg.equal",
|
|
1493
|
-
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
|
|
1494
|
-
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
|
|
1495
|
-
[DataValidationOperator.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
|
|
1496
|
-
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
|
|
1497
|
-
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
|
|
1498
|
-
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
|
|
1499
|
-
}, TWO_FORMULA_OPERATOR_COUNT = [
|
|
1500
|
-
DataValidationOperator.BETWEEN,
|
|
1501
|
-
DataValidationOperator.NOT_BETWEEN
|
|
1502
|
-
], FORMULA1$1 = "{FORMULA1}", FORMULA2$1 = "{FORMULA2}", transformDate2SerialNumber = /* @__PURE__ */ __name((value) => {
|
|
1503
|
-
var _a12, _b;
|
|
5
|
+
import { D as DataValidationFormulaService, g as getFormulaResult, i as isLegalFormulaResult, a as DateOperatorNameMap, b as DateOperatorTitleMap, c as DateOperatorErrorTitleMap, d as dayjs, T as TWO_FORMULA_OPERATOR_COUNT, e as getCellValueOrigin, f as DataValidationCustomFormulaService, h as getFormulaCellData, S as SheetDataValidationModel, C as CheckboxValidator, j as getDataValidationDiffMutations, r as removeDataValidationUndoFactory, k as DataValidationCacheService, l as SheetsDataValidationValidatorService, A as AddSheetDataValidationCommand, U as UpdateSheetDataValidationRangeCommand, m as UpdateSheetDataValidationSettingCommand, n as UpdateSheetDataValidationOptionsCommand, R as RemoveSheetDataValidationCommand, o as RemoveSheetAllDataValidationCommand, p as ClearRangeDataValidationCommand } from "../dv-validator-service-9VDfOza1.mjs";
|
|
6
|
+
import { q, s, t } from "../dv-validator-service-9VDfOza1.mjs";
|
|
7
|
+
import { DataValidationType, DataValidationOperator, isFormulaString, numfmt, Tools, IUniverInstanceService, DataValidationRenderMode, UniverInstanceType, WrapStrategy, Rectangle, CellValueType, Inject, Injector, RxDisposable, toDisposable, Disposable, IPermissionService, isRangesEqual, DependentOn, Plugin, ICommandService, IConfigService } from "@univerjs/core";
|
|
8
|
+
import { BaseDataValidator, TextLengthErrorTitleMap, DataValidatorRegistryService, UpdateRuleType, UpdateDataValidationMutation, RemoveDataValidationMutation, AddDataValidationMutation, UniverDataValidationPlugin } from "@univerjs/data-validation";
|
|
9
|
+
import { SheetsSelectionsService, SheetInterceptorService, ClearSelectionAllCommand, WorksheetViewPermission, RefRangeService, handleCommonDefaultRangeChangeWithEffectRefCommands, RemoveSheetCommand } from "@univerjs/sheets";
|
|
10
|
+
import { LexerTreeBuilder, isReferenceString, sequenceNodeType, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache } from "@univerjs/engine-formula";
|
|
11
|
+
import { FormulaRefRangeService } from "@univerjs/sheets-formula";
|
|
12
|
+
const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN", FORMULA1$1 = "{FORMULA1}", FORMULA2$1 = "{FORMULA2}", transformDate2SerialNumber = /* @__PURE__ */ __name((value) => {
|
|
13
|
+
var _a6, _b;
|
|
1504
14
|
if (value == null || typeof value == "boolean")
|
|
1505
15
|
return;
|
|
1506
16
|
if (typeof value == "number" || !Number.isNaN(+value))
|
|
1507
17
|
return +value;
|
|
1508
|
-
const v = (
|
|
18
|
+
const v = (_a6 = numfmt.parseDate(value)) == null ? void 0 : _a6.v;
|
|
1509
19
|
return Tools.isDefine(v) ? v : (_b = numfmt.parseDate(dayjs(value).format("YYYY-MM-DD HH:mm:ss"))) == null ? void 0 : _b.v;
|
|
1510
20
|
}, "transformDate2SerialNumber"), _DateValidator = class _DateValidator extends BaseDataValidator {
|
|
1511
21
|
constructor() {
|
|
@@ -1526,18 +36,19 @@ const DateOperatorTitleMap = {
|
|
|
1526
36
|
__publicField(this, "_formulaService", this.injector.get(DataValidationFormulaService));
|
|
1527
37
|
}
|
|
1528
38
|
async parseFormula(rule, unitId, subUnitId) {
|
|
1529
|
-
var
|
|
1530
|
-
const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
|
|
39
|
+
var _a6, _b;
|
|
40
|
+
const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formulaResult1 = getFormulaResult((_a6 = results == null ? void 0 : results[0]) == null ? void 0 : _a6.result), formulaResult2 = getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1)) && isLegalFormulaResult(String(formulaResult2));
|
|
1531
41
|
return {
|
|
1532
|
-
formula1: transformDate2SerialNumber(isFormulaString(formula1) ?
|
|
1533
|
-
formula2: transformDate2SerialNumber(isFormulaString(formula2) ?
|
|
42
|
+
formula1: transformDate2SerialNumber(isFormulaString(formula1) ? formulaResult1 : formula1),
|
|
43
|
+
formula2: transformDate2SerialNumber(isFormulaString(formula2) ? formulaResult2 : formula2),
|
|
44
|
+
isFormulaValid
|
|
1534
45
|
};
|
|
1535
46
|
}
|
|
1536
47
|
parseFormulaSync(rule, unitId, subUnitId) {
|
|
1537
|
-
var
|
|
48
|
+
var _a6, _b;
|
|
1538
49
|
const results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
|
|
1539
50
|
return {
|
|
1540
|
-
formula1: transformDate2SerialNumber(isFormulaString(formula1) ? getFormulaResult((
|
|
51
|
+
formula1: transformDate2SerialNumber(isFormulaString(formula1) ? getFormulaResult((_a6 = results == null ? void 0 : results[0]) == null ? void 0 : _a6.result) : formula1),
|
|
1541
52
|
formula2: transformDate2SerialNumber(isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2)
|
|
1542
53
|
};
|
|
1543
54
|
}
|
|
@@ -1570,14 +81,14 @@ const DateOperatorTitleMap = {
|
|
|
1570
81
|
}
|
|
1571
82
|
normalizeFormula(rule, _unitId, _subUnitId) {
|
|
1572
83
|
const { formula1, formula2, bizInfo } = rule, normlizeSingleFormula = /* @__PURE__ */ __name((formula) => {
|
|
1573
|
-
var
|
|
84
|
+
var _a6;
|
|
1574
85
|
if (!formula)
|
|
1575
86
|
return formula;
|
|
1576
87
|
let date;
|
|
1577
88
|
if (!Number.isNaN(+formula))
|
|
1578
89
|
date = numfmt.dateFromSerial(+formula);
|
|
1579
90
|
else {
|
|
1580
|
-
const res = (
|
|
91
|
+
const res = (_a6 = numfmt.parseDate(formula)) == null ? void 0 : _a6.v;
|
|
1581
92
|
if (res == null)
|
|
1582
93
|
return "";
|
|
1583
94
|
date = numfmt.dateFromSerial(res);
|
|
@@ -1638,15 +149,15 @@ const DateOperatorTitleMap = {
|
|
|
1638
149
|
return this.operators.map((operator) => this.localeService.t(DateOperatorNameMap[operator]));
|
|
1639
150
|
}
|
|
1640
151
|
generateRuleName(rule) {
|
|
1641
|
-
var
|
|
152
|
+
var _a6, _b;
|
|
1642
153
|
if (!rule.operator)
|
|
1643
154
|
return this.titleStr;
|
|
1644
|
-
const ruleName = this.localeService.t(DateOperatorTitleMap[rule.operator]).replace(FORMULA1$1, (
|
|
155
|
+
const ruleName = this.localeService.t(DateOperatorTitleMap[rule.operator]).replace(FORMULA1$1, (_a6 = rule.formula1) != null ? _a6 : "").replace(FORMULA2$1, (_b = rule.formula2) != null ? _b : "");
|
|
1645
156
|
return `${this.titleStr} ${ruleName}`;
|
|
1646
157
|
}
|
|
1647
158
|
generateRuleErrorMessage(rule) {
|
|
1648
|
-
var
|
|
1649
|
-
return rule.operator ? `${this.localeService.t(DateOperatorErrorTitleMap[rule.operator]).replace(FORMULA1$1, (
|
|
159
|
+
var _a6, _b;
|
|
160
|
+
return rule.operator ? `${this.localeService.t(DateOperatorErrorTitleMap[rule.operator]).replace(FORMULA1$1, (_a6 = rule.formula1) != null ? _a6 : "").replace(FORMULA2$1, (_b = rule.formula2) != null ? _b : "")}` : this.titleStr;
|
|
1650
161
|
}
|
|
1651
162
|
};
|
|
1652
163
|
__name(_DateValidator, "DateValidator");
|
|
@@ -1692,11 +203,12 @@ const _DecimalValidator = class _DecimalValidator extends BaseDataValidator {
|
|
|
1692
203
|
return formula == null ? Number.NaN : +formula;
|
|
1693
204
|
}
|
|
1694
205
|
async parseFormula(rule, unitId, subUnitId) {
|
|
1695
|
-
var
|
|
1696
|
-
const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
|
|
206
|
+
var _a6, _b;
|
|
207
|
+
const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formulaResult1 = getFormulaResult((_a6 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a6.result), formulaResult2 = getFormulaResult((_b = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _b.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1)) && isLegalFormulaResult(String(formulaResult2));
|
|
1697
208
|
return {
|
|
1698
|
-
formula1: this._parseNumber(isFormulaString(formula1) ?
|
|
1699
|
-
formula2: this._parseNumber(isFormulaString(formula2) ?
|
|
209
|
+
formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 : formula1),
|
|
210
|
+
formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 : formula2),
|
|
211
|
+
isFormulaValid
|
|
1700
212
|
};
|
|
1701
213
|
}
|
|
1702
214
|
validatorFormula(rule, unitId, subUnitId) {
|
|
@@ -1776,14 +288,14 @@ function getRuleFormulaResultSet(result) {
|
|
|
1776
288
|
return result.forEach(
|
|
1777
289
|
(row) => {
|
|
1778
290
|
row.forEach((cell) => {
|
|
1779
|
-
var
|
|
291
|
+
var _a6, _b;
|
|
1780
292
|
const value = getCellValueOrigin(cell);
|
|
1781
293
|
if (value != null) {
|
|
1782
|
-
if (typeof value != "string" && typeof (cell == null ? void 0 : cell.s) == "object" && ((_b = (
|
|
294
|
+
if (typeof value != "string" && typeof (cell == null ? void 0 : cell.s) == "object" && ((_b = (_a6 = cell.s) == null ? void 0 : _a6.n) != null && _b.pattern)) {
|
|
1783
295
|
resultSet.add(numfmt.format(cell.s.n.pattern, value, { throws: !1 }));
|
|
1784
296
|
return;
|
|
1785
297
|
}
|
|
1786
|
-
resultSet.add(value.toString());
|
|
298
|
+
isLegalFormulaResult(value.toString()) && resultSet.add(value.toString());
|
|
1787
299
|
}
|
|
1788
300
|
});
|
|
1789
301
|
}
|
|
@@ -1826,16 +338,16 @@ const _ListValidator = class _ListValidator extends BaseDataValidator {
|
|
|
1826
338
|
__publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name((rule) => rule.renderMode !== DataValidationRenderMode.TEXT, "skipDefaultFontRender"));
|
|
1827
339
|
}
|
|
1828
340
|
validatorFormula(rule, unitId, subUnitId) {
|
|
1829
|
-
var
|
|
1830
|
-
const success = !Tools.isBlank(rule.formula1), valid = isValidListFormula((
|
|
341
|
+
var _a6, _b, _c;
|
|
342
|
+
const success = !Tools.isBlank(rule.formula1), valid = isValidListFormula((_a6 = rule.formula1) != null ? _a6 : "", 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 : "");
|
|
1831
343
|
return {
|
|
1832
344
|
success: !!(success && valid && !isIntersects),
|
|
1833
345
|
formula1: success ? valid ? isIntersects ? this.localeService.t("dataValidation.validFail.listIntersects") : void 0 : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
|
|
1834
346
|
};
|
|
1835
347
|
}
|
|
1836
348
|
getExtraStyle(rule, value, { style: defaultStyle }) {
|
|
1837
|
-
var
|
|
1838
|
-
const tb = (
|
|
349
|
+
var _a6;
|
|
350
|
+
const tb = (_a6 = defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) != null ? _a6 : WrapStrategy.WRAP;
|
|
1839
351
|
if (rule.type === DataValidationType.LIST && (rule.renderMode === DataValidationRenderMode.ARROW || rule.renderMode === DataValidationRenderMode.TEXT)) {
|
|
1840
352
|
const colorMap = this.getListWithColorMap(rule), valueStr = `${value != null ? value : ""}`, color = colorMap[valueStr];
|
|
1841
353
|
if (color)
|
|
@@ -1855,11 +367,12 @@ const _ListValidator = class _ListValidator extends BaseDataValidator {
|
|
|
1855
367
|
return deserializeListOptions(cellString);
|
|
1856
368
|
}
|
|
1857
369
|
async parseFormula(rule, unitId, subUnitId) {
|
|
1858
|
-
var
|
|
1859
|
-
const { formula1 = "" } = rule, results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
|
|
370
|
+
var _a6, _b;
|
|
371
|
+
const { formula1 = "" } = rule, results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), formulaResult1 = getFormulaResult((_a6 = results == null ? void 0 : results[0]) == null ? void 0 : _a6.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1));
|
|
1860
372
|
return {
|
|
1861
|
-
formula1: isFormulaString(formula1) ? getRuleFormulaResultSet((
|
|
1862
|
-
formula2: void 0
|
|
373
|
+
formula1: isFormulaString(formula1) ? getRuleFormulaResultSet((_b = results == null ? void 0 : results[0]) == null ? void 0 : _b.result) : deserializeListOptions(formula1),
|
|
374
|
+
formula2: void 0,
|
|
375
|
+
isFormulaValid
|
|
1863
376
|
};
|
|
1864
377
|
}
|
|
1865
378
|
async isValidType(cellInfo, formula, rule) {
|
|
@@ -1873,8 +386,8 @@ const _ListValidator = class _ListValidator extends BaseDataValidator {
|
|
|
1873
386
|
return this.localeService.t("dataValidation.list.error");
|
|
1874
387
|
}
|
|
1875
388
|
getList(rule, currentUnitId, currentSubUnitId) {
|
|
1876
|
-
var
|
|
1877
|
-
const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (
|
|
389
|
+
var _a6, _b, _c;
|
|
390
|
+
const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (_a6 = currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : void 0) != null ? _a6 : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
1878
391
|
if (!workbook) return [];
|
|
1879
392
|
const worksheet = (_b = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) != null ? _b : workbook.getActiveSheet();
|
|
1880
393
|
if (!worksheet) return [];
|
|
@@ -1882,8 +395,8 @@ const _ListValidator = class _ListValidator extends BaseDataValidator {
|
|
|
1882
395
|
return isFormulaString(formula1) ? getRuleFormulaResultSet((_c = results == null ? void 0 : results[0]) == null ? void 0 : _c.result) : deserializeListOptions(formula1);
|
|
1883
396
|
}
|
|
1884
397
|
async getListAsync(rule, currentUnitId, currentSubUnitId) {
|
|
1885
|
-
var
|
|
1886
|
-
const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (
|
|
398
|
+
var _a6, _b, _c;
|
|
399
|
+
const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (_a6 = currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : void 0) != null ? _a6 : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
1887
400
|
if (!workbook) return [];
|
|
1888
401
|
const worksheet = (_b = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) != null ? _b : workbook.getActiveSheet();
|
|
1889
402
|
if (!worksheet) return [];
|
|
@@ -1947,11 +460,12 @@ const FORMULA1 = "{FORMULA1}", FORMULA2 = "{FORMULA2}", _TextLengthValidator = c
|
|
|
1947
460
|
return !Number.isNaN(formula);
|
|
1948
461
|
}
|
|
1949
462
|
async parseFormula(rule, unitId, subUnitId) {
|
|
1950
|
-
var
|
|
1951
|
-
const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
|
|
463
|
+
var _a6, _b;
|
|
464
|
+
const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formulaResult1 = getFormulaResult((_a6 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a6.result), formulaResult2 = getFormulaResult((_b = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _b.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1)) && isLegalFormulaResult(String(formulaResult2));
|
|
1952
465
|
return {
|
|
1953
|
-
formula1: this._parseNumber(isFormulaString(formula1) ?
|
|
1954
|
-
formula2: this._parseNumber(isFormulaString(formula2) ?
|
|
466
|
+
formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 : formula1),
|
|
467
|
+
formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 : formula2),
|
|
468
|
+
isFormulaValid
|
|
1955
469
|
};
|
|
1956
470
|
}
|
|
1957
471
|
transform(cellInfo, _formula, _rule) {
|
|
@@ -2003,396 +517,41 @@ const FORMULA1 = "{FORMULA1}", FORMULA2 = "{FORMULA2}", _TextLengthValidator = c
|
|
|
2003
517
|
return this._isValidFormula(formula1) ? cellValue <= formula1 : !1;
|
|
2004
518
|
}
|
|
2005
519
|
generateRuleErrorMessage(rule) {
|
|
2006
|
-
var
|
|
2007
|
-
return rule.operator ? `${this.localeService.t(TextLengthErrorTitleMap[rule.operator]).replace(FORMULA1, (
|
|
520
|
+
var _a6, _b;
|
|
521
|
+
return rule.operator ? `${this.localeService.t(TextLengthErrorTitleMap[rule.operator]).replace(FORMULA1, (_a6 = rule.formula1) != null ? _a6 : "").replace(FORMULA2, (_b = rule.formula2) != null ? _b : "")}` : this.titleStr;
|
|
2008
522
|
}
|
|
2009
523
|
};
|
|
2010
524
|
__name(_TextLengthValidator, "TextLengthValidator");
|
|
2011
525
|
let TextLengthValidator = _TextLengthValidator;
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
526
|
+
const PLUGIN_CONFIG_KEY = "sheets-data-validation.config", defaultPluginConfig = {}, _AnyValidator = class _AnyValidator extends BaseDataValidator {
|
|
527
|
+
constructor() {
|
|
528
|
+
super(...arguments);
|
|
529
|
+
__publicField(this, "id", DataValidationType.ANY);
|
|
530
|
+
__publicField(this, "title", "dataValidation.any.title");
|
|
531
|
+
__publicField(this, "operators", []);
|
|
532
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
533
|
+
}
|
|
534
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
2020
535
|
return {
|
|
2021
|
-
|
|
2022
|
-
|
|
536
|
+
formula1: rule.formula1,
|
|
537
|
+
formula2: rule.formula2,
|
|
538
|
+
isFormulaValid: !0
|
|
2023
539
|
};
|
|
2024
|
-
const { worksheet } = target, redoMatrix = new ObjectMatrix();
|
|
2025
|
-
function setRangesDefaultValue(ranges, defaultValue) {
|
|
2026
|
-
fillDefaultValue && ranges.forEach((range) => {
|
|
2027
|
-
Range.foreach(range, (row, column) => {
|
|
2028
|
-
const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
|
|
2029
|
-
(isBlankCell(cellData) || value === defaultValue) && redoMatrix.setValue(row, column, {
|
|
2030
|
-
v: defaultValue,
|
|
2031
|
-
p: null
|
|
2032
|
-
});
|
|
2033
|
-
});
|
|
2034
|
-
});
|
|
2035
540
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
unitId,
|
|
2051
|
-
subUnitId,
|
|
2052
|
-
rule: diff.rule,
|
|
2053
|
-
index: diff.index,
|
|
2054
|
-
source
|
|
2055
|
-
}
|
|
2056
|
-
});
|
|
2057
|
-
break;
|
|
2058
|
-
case "update": {
|
|
2059
|
-
redoMutations.push({
|
|
2060
|
-
id: UpdateDataValidationMutation.id,
|
|
2061
|
-
params: {
|
|
2062
|
-
unitId,
|
|
2063
|
-
subUnitId,
|
|
2064
|
-
ruleId: diff.ruleId,
|
|
2065
|
-
payload: {
|
|
2066
|
-
type: UpdateRuleType.RANGE,
|
|
2067
|
-
payload: diff.newRanges
|
|
2068
|
-
},
|
|
2069
|
-
source
|
|
2070
|
-
}
|
|
2071
|
-
}), undoMutations.unshift({
|
|
2072
|
-
id: UpdateDataValidationMutation.id,
|
|
2073
|
-
params: {
|
|
2074
|
-
unitId,
|
|
2075
|
-
subUnitId,
|
|
2076
|
-
ruleId: diff.ruleId,
|
|
2077
|
-
payload: {
|
|
2078
|
-
type: UpdateRuleType.RANGE,
|
|
2079
|
-
payload: diff.oldRanges
|
|
2080
|
-
},
|
|
2081
|
-
source
|
|
2082
|
-
}
|
|
2083
|
-
});
|
|
2084
|
-
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, diff.ruleId);
|
|
2085
|
-
if (rule && rule.type === DataValidationType.CHECKBOX) {
|
|
2086
|
-
const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(rule, unitId, subUnitId);
|
|
2087
|
-
setRangesDefaultValue(diff.newRanges, formula.formula2);
|
|
2088
|
-
}
|
|
2089
|
-
break;
|
|
2090
|
-
}
|
|
2091
|
-
case "add": {
|
|
2092
|
-
if (redoMutations.push({
|
|
2093
|
-
id: AddDataValidationMutation.id,
|
|
2094
|
-
params: {
|
|
2095
|
-
unitId,
|
|
2096
|
-
subUnitId,
|
|
2097
|
-
rule: diff.rule,
|
|
2098
|
-
source
|
|
2099
|
-
}
|
|
2100
|
-
}), undoMutations.unshift({
|
|
2101
|
-
id: RemoveDataValidationMutation.id,
|
|
2102
|
-
params: {
|
|
2103
|
-
unitId,
|
|
2104
|
-
subUnitId,
|
|
2105
|
-
ruleId: diff.rule.uid,
|
|
2106
|
-
source
|
|
2107
|
-
}
|
|
2108
|
-
}), diff.rule.type === DataValidationType.CHECKBOX) {
|
|
2109
|
-
const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
|
|
2110
|
-
setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
|
|
2111
|
-
}
|
|
2112
|
-
break;
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
});
|
|
2116
|
-
const redoSetRangeValues = {
|
|
2117
|
-
id: SetRangeValuesMutation.id,
|
|
2118
|
-
params: {
|
|
2119
|
-
unitId,
|
|
2120
|
-
subUnitId,
|
|
2121
|
-
cellValue: redoMatrix.getData()
|
|
2122
|
-
}
|
|
2123
|
-
}, undoSetRangeValues = {
|
|
2124
|
-
id: SetRangeValuesMutation.id,
|
|
2125
|
-
params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
|
|
2126
|
-
};
|
|
2127
|
-
return redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues), {
|
|
2128
|
-
redoMutations,
|
|
2129
|
-
undoMutations
|
|
2130
|
-
};
|
|
2131
|
-
}
|
|
2132
|
-
__name(getDataValidationDiffMutations, "getDataValidationDiffMutations");
|
|
2133
|
-
const UpdateSheetDataValidationRangeCommand = {
|
|
2134
|
-
type: CommandType.COMMAND,
|
|
2135
|
-
id: "sheet.command.updateDataValidationRuleRange",
|
|
2136
|
-
handler(accessor, params) {
|
|
2137
|
-
if (!params)
|
|
2138
|
-
return !1;
|
|
2139
|
-
const { unitId, subUnitId, ranges, ruleId } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService);
|
|
2140
|
-
if (!sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId))
|
|
2141
|
-
return !1;
|
|
2142
|
-
const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
2143
|
-
matrix.updateRange(ruleId, ranges);
|
|
2144
|
-
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
2145
|
-
return undoRedoService.pushUndoRedo({
|
|
2146
|
-
undoMutations,
|
|
2147
|
-
redoMutations,
|
|
2148
|
-
unitID: unitId
|
|
2149
|
-
}), sequenceExecute(redoMutations, commandService), !0;
|
|
2150
|
-
}
|
|
2151
|
-
}, AddSheetDataValidationCommand = {
|
|
2152
|
-
type: CommandType.COMMAND,
|
|
2153
|
-
id: "sheet.command.addDataValidation",
|
|
2154
|
-
handler(accessor, params) {
|
|
2155
|
-
if (!params)
|
|
2156
|
-
return !1;
|
|
2157
|
-
const { unitId, subUnitId, rule } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
2158
|
-
matrix.addRule(rule);
|
|
2159
|
-
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), mutationParams = {
|
|
2160
|
-
unitId,
|
|
2161
|
-
subUnitId,
|
|
2162
|
-
rule
|
|
2163
|
-
}, { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
2164
|
-
return redoMutations.push({
|
|
2165
|
-
id: AddDataValidationMutation.id,
|
|
2166
|
-
params: mutationParams
|
|
2167
|
-
}), undoMutations.unshift({
|
|
2168
|
-
id: RemoveDataValidationMutation.id,
|
|
2169
|
-
params: {
|
|
2170
|
-
unitId,
|
|
2171
|
-
subUnitId,
|
|
2172
|
-
ruleId: rule.uid
|
|
2173
|
-
}
|
|
2174
|
-
}), undoRedoService.pushUndoRedo({
|
|
2175
|
-
unitID: unitId,
|
|
2176
|
-
redoMutations,
|
|
2177
|
-
undoMutations
|
|
2178
|
-
}), sequenceExecute(redoMutations, commandService), !0;
|
|
2179
|
-
}
|
|
2180
|
-
}, UpdateSheetDataValidationSettingCommand = {
|
|
2181
|
-
type: CommandType.COMMAND,
|
|
2182
|
-
id: "sheets.command.update-data-validation-setting",
|
|
2183
|
-
// eslint-disable-next-line max-lines-per-function
|
|
2184
|
-
handler(accessor, params) {
|
|
2185
|
-
if (!params)
|
|
2186
|
-
return !1;
|
|
2187
|
-
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);
|
|
2188
|
-
if (!validator)
|
|
2189
|
-
return !1;
|
|
2190
|
-
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
2191
|
-
if (!rule)
|
|
2192
|
-
return !1;
|
|
2193
|
-
const newRule = { ...rule, ...setting };
|
|
2194
|
-
if (!validator.validatorFormula(newRule, unitId, subUnitId).success)
|
|
2195
|
-
return !1;
|
|
2196
|
-
const mutationParams = {
|
|
2197
|
-
unitId,
|
|
2198
|
-
subUnitId,
|
|
2199
|
-
ruleId,
|
|
2200
|
-
payload: {
|
|
2201
|
-
type: UpdateRuleType.SETTING,
|
|
2202
|
-
payload: {
|
|
2203
|
-
...setting,
|
|
2204
|
-
...validator.normalizeFormula(newRule, unitId, subUnitId)
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
}, redoMutations = [{
|
|
2208
|
-
id: UpdateDataValidationMutation.id,
|
|
2209
|
-
params: mutationParams
|
|
2210
|
-
}], undoMutationParams = {
|
|
2211
|
-
unitId,
|
|
2212
|
-
subUnitId,
|
|
2213
|
-
ruleId,
|
|
2214
|
-
payload: {
|
|
2215
|
-
type: UpdateRuleType.SETTING,
|
|
2216
|
-
payload: getRuleSetting(rule)
|
|
2217
|
-
}
|
|
2218
|
-
}, undoMutations = [{
|
|
2219
|
-
id: UpdateDataValidationMutation.id,
|
|
2220
|
-
params: undoMutationParams
|
|
2221
|
-
}];
|
|
2222
|
-
if (setting.type === DataValidationType.CHECKBOX) {
|
|
2223
|
-
const ranges = rule.ranges, univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
|
|
2224
|
-
if (target) {
|
|
2225
|
-
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;
|
|
2226
|
-
ranges.forEach((range) => {
|
|
2227
|
-
Range.foreach(range, (row, column) => {
|
|
2228
|
-
const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
|
|
2229
|
-
isBlankCell(cellData) || value === String(oldFormula2) ? redoMatrix.setValue(row, column, {
|
|
2230
|
-
v: formula2,
|
|
2231
|
-
p: null
|
|
2232
|
-
}) : value === String(oldFormula1) && redoMatrix.setValue(row, column, {
|
|
2233
|
-
v: formula1,
|
|
2234
|
-
p: null
|
|
2235
|
-
});
|
|
2236
|
-
});
|
|
2237
|
-
});
|
|
2238
|
-
const redoSetRangeValues = {
|
|
2239
|
-
id: SetRangeValuesMutation.id,
|
|
2240
|
-
params: {
|
|
2241
|
-
unitId,
|
|
2242
|
-
subUnitId,
|
|
2243
|
-
cellValue: redoMatrix.getData()
|
|
2244
|
-
}
|
|
2245
|
-
}, undoSetRangeValues = {
|
|
2246
|
-
id: SetRangeValuesMutation.id,
|
|
2247
|
-
params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
|
|
2248
|
-
};
|
|
2249
|
-
redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues);
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
return sequenceExecute(redoMutations, commandService).result ? (redoUndoService.pushUndoRedo({
|
|
2253
|
-
unitID: unitId,
|
|
2254
|
-
redoMutations,
|
|
2255
|
-
undoMutations
|
|
2256
|
-
}), !0) : !1;
|
|
2257
|
-
}
|
|
2258
|
-
}, UpdateSheetDataValidationOptionsCommand = {
|
|
2259
|
-
type: CommandType.COMMAND,
|
|
2260
|
-
id: "sheets.command.update-data-validation-options",
|
|
2261
|
-
handler(accessor, params) {
|
|
2262
|
-
if (!params)
|
|
2263
|
-
return !1;
|
|
2264
|
-
const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, options } = params, rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
2265
|
-
if (!rule)
|
|
2266
|
-
return !1;
|
|
2267
|
-
const mutationParams = {
|
|
2268
|
-
unitId,
|
|
2269
|
-
subUnitId,
|
|
2270
|
-
ruleId,
|
|
2271
|
-
payload: {
|
|
2272
|
-
type: UpdateRuleType.OPTIONS,
|
|
2273
|
-
payload: options
|
|
2274
|
-
}
|
|
2275
|
-
}, redoMutations = [{
|
|
2276
|
-
id: UpdateDataValidationMutation.id,
|
|
2277
|
-
params: mutationParams
|
|
2278
|
-
}], undoMutationParams = {
|
|
2279
|
-
unitId,
|
|
2280
|
-
subUnitId,
|
|
2281
|
-
ruleId,
|
|
2282
|
-
payload: {
|
|
2283
|
-
type: UpdateRuleType.OPTIONS,
|
|
2284
|
-
payload: getRuleOptions(rule)
|
|
2285
|
-
}
|
|
2286
|
-
}, undoMutations = [{
|
|
2287
|
-
id: UpdateDataValidationMutation.id,
|
|
2288
|
-
params: undoMutationParams
|
|
2289
|
-
}];
|
|
2290
|
-
return redoUndoService.pushUndoRedo({
|
|
2291
|
-
unitID: unitId,
|
|
2292
|
-
redoMutations,
|
|
2293
|
-
undoMutations
|
|
2294
|
-
}), commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams), !0;
|
|
2295
|
-
}
|
|
2296
|
-
}, ClearRangeDataValidationCommand = {
|
|
2297
|
-
type: CommandType.COMMAND,
|
|
2298
|
-
id: "sheets.command.clear-range-data-validation",
|
|
2299
|
-
handler(accessor, params) {
|
|
2300
|
-
if (!params)
|
|
2301
|
-
return !1;
|
|
2302
|
-
const { unitId, subUnitId, ranges } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId }), sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
2303
|
-
if (!target) return !1;
|
|
2304
|
-
const undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
2305
|
-
matrix.removeRange(ranges);
|
|
2306
|
-
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
2307
|
-
return undoRedoService.pushUndoRedo({
|
|
2308
|
-
unitID: unitId,
|
|
2309
|
-
redoMutations,
|
|
2310
|
-
undoMutations
|
|
2311
|
-
}), sequenceExecute(redoMutations, commandService).result;
|
|
2312
|
-
}
|
|
2313
|
-
}, RemoveSheetAllDataValidationCommand = {
|
|
2314
|
-
type: CommandType.COMMAND,
|
|
2315
|
-
id: "sheet.command.remove-all-data-validation",
|
|
2316
|
-
handler(accessor, params) {
|
|
2317
|
-
if (!params)
|
|
2318
|
-
return !1;
|
|
2319
|
-
const { unitId, subUnitId } = params, commandService = accessor.get(ICommandService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), undoRedoService = accessor.get(IUndoRedoService), currentRules = [...sheetDataValidationModel.getRules(unitId, subUnitId)], redoParams = {
|
|
2320
|
-
unitId,
|
|
2321
|
-
subUnitId,
|
|
2322
|
-
ruleId: currentRules.map((rule) => rule.uid)
|
|
2323
|
-
}, redoMutations = [{
|
|
2324
|
-
id: RemoveDataValidationMutation.id,
|
|
2325
|
-
params: redoParams
|
|
2326
|
-
}], undoMutations = [{
|
|
2327
|
-
id: AddDataValidationMutation.id,
|
|
2328
|
-
params: {
|
|
2329
|
-
unitId,
|
|
2330
|
-
subUnitId,
|
|
2331
|
-
rule: currentRules
|
|
2332
|
-
}
|
|
2333
|
-
}];
|
|
2334
|
-
return undoRedoService.pushUndoRedo({
|
|
2335
|
-
redoMutations,
|
|
2336
|
-
undoMutations,
|
|
2337
|
-
unitID: unitId
|
|
2338
|
-
}), commandService.executeCommand(RemoveDataValidationMutation.id, redoParams), !0;
|
|
2339
|
-
}
|
|
2340
|
-
}, removeDataValidationUndoFactory = /* @__PURE__ */ __name((accessor, redoParams) => {
|
|
2341
|
-
const sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, source } = redoParams;
|
|
2342
|
-
if (Array.isArray(ruleId)) {
|
|
2343
|
-
const rules = ruleId.map((id) => sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
2344
|
-
return [{
|
|
2345
|
-
id: AddDataValidationMutation.id,
|
|
2346
|
-
params: {
|
|
2347
|
-
unitId,
|
|
2348
|
-
subUnitId,
|
|
2349
|
-
rule: rules,
|
|
2350
|
-
source
|
|
2351
|
-
}
|
|
2352
|
-
}];
|
|
2353
|
-
}
|
|
2354
|
-
return [{
|
|
2355
|
-
id: AddDataValidationMutation.id,
|
|
2356
|
-
params: {
|
|
2357
|
-
unitId,
|
|
2358
|
-
subUnitId,
|
|
2359
|
-
rule: {
|
|
2360
|
-
...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
|
|
2361
|
-
},
|
|
2362
|
-
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
2363
|
-
}
|
|
2364
|
-
}];
|
|
2365
|
-
}, "removeDataValidationUndoFactory"), RemoveSheetDataValidationCommand = {
|
|
2366
|
-
type: CommandType.COMMAND,
|
|
2367
|
-
id: "sheet.command.remove-data-validation-rule",
|
|
2368
|
-
handler(accessor, params) {
|
|
2369
|
-
if (!params)
|
|
2370
|
-
return !1;
|
|
2371
|
-
const { unitId, subUnitId, ruleId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), redoMutations = [{
|
|
2372
|
-
id: RemoveDataValidationMutation.id,
|
|
2373
|
-
params
|
|
2374
|
-
}], undoMutations = [{
|
|
2375
|
-
id: AddDataValidationMutation.id,
|
|
2376
|
-
params: {
|
|
2377
|
-
unitId,
|
|
2378
|
-
subUnitId,
|
|
2379
|
-
rule: {
|
|
2380
|
-
...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
|
|
2381
|
-
},
|
|
2382
|
-
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
2383
|
-
}
|
|
2384
|
-
}];
|
|
2385
|
-
return undoRedoService.pushUndoRedo({
|
|
2386
|
-
undoMutations,
|
|
2387
|
-
redoMutations,
|
|
2388
|
-
unitID: params.unitId
|
|
2389
|
-
}), commandService.executeCommand(RemoveDataValidationMutation.id, params), !0;
|
|
2390
|
-
}
|
|
2391
|
-
}, PLUGIN_CONFIG_KEY = "sheets-data-validation.config", defaultPluginConfig = {};
|
|
2392
|
-
function isLegalFormulaResult(res) {
|
|
2393
|
-
return !ERROR_TYPE_SET.has(res);
|
|
2394
|
-
}
|
|
2395
|
-
__name(isLegalFormulaResult, "isLegalFormulaResult");
|
|
541
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
542
|
+
return {
|
|
543
|
+
success: !0
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
async isValidType(cellInfo, formula, rule) {
|
|
547
|
+
return !0;
|
|
548
|
+
}
|
|
549
|
+
generateRuleErrorMessage(rule) {
|
|
550
|
+
return this.localeService.t("dataValidation.any.error");
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
__name(_AnyValidator, "AnyValidator");
|
|
554
|
+
let AnyValidator = _AnyValidator;
|
|
2396
555
|
const _CustomFormulaValidator = class _CustomFormulaValidator extends BaseDataValidator {
|
|
2397
556
|
constructor() {
|
|
2398
557
|
super(...arguments);
|
|
@@ -2412,16 +571,21 @@ const _CustomFormulaValidator = class _CustomFormulaValidator extends BaseDataVa
|
|
|
2412
571
|
async parseFormula(_rule, _unitId, _subUnitId) {
|
|
2413
572
|
return {
|
|
2414
573
|
formula1: void 0,
|
|
2415
|
-
formula2: void 0
|
|
574
|
+
formula2: void 0,
|
|
575
|
+
isFormulaValid: !1
|
|
2416
576
|
};
|
|
2417
577
|
}
|
|
2418
578
|
async isValidType(cellInfo, _formula, _rule) {
|
|
2419
579
|
const { column, row, unitId, subUnitId } = cellInfo, result = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, row, column), cellData = getFormulaCellData(result == null ? void 0 : result.result), formulaResult = cellData == null ? void 0 : cellData.v;
|
|
2420
|
-
return Tools.isDefine(formulaResult) && formulaResult !== "" ? cellData.t === CellValueType.BOOLEAN ? !!formulaResult : typeof formulaResult == "boolean" ? formulaResult : typeof formulaResult == "number" ? !!formulaResult : typeof formulaResult == "string" ? isLegalFormulaResult(formulaResult) : !!formulaResult : !1;
|
|
580
|
+
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;
|
|
2421
581
|
}
|
|
2422
582
|
generateRuleErrorMessage(rule) {
|
|
2423
583
|
return this.localeService.t("dataValidation.custom.error");
|
|
2424
584
|
}
|
|
585
|
+
generateRuleName(rule) {
|
|
586
|
+
var _a6;
|
|
587
|
+
return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (_a6 = rule.formula1) != null ? _a6 : "");
|
|
588
|
+
}
|
|
2425
589
|
};
|
|
2426
590
|
__name(_CustomFormulaValidator, "CustomFormulaValidator");
|
|
2427
591
|
let CustomFormulaValidator = _CustomFormulaValidator;
|
|
@@ -2471,11 +635,12 @@ const _WholeValidator = class _WholeValidator extends BaseDataValidator {
|
|
|
2471
635
|
return formula == null ? Number.NaN : +formula;
|
|
2472
636
|
}
|
|
2473
637
|
async parseFormula(rule, unitId, subUnitId) {
|
|
2474
|
-
var
|
|
2475
|
-
const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
|
|
638
|
+
var _a6, _b, _c, _d, _e, _f, _g, _h;
|
|
639
|
+
const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formula1Result = isFormulaString(formula1) ? (_d = (_c = (_b = (_a6 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a6.result) == null ? void 0 : _b[0]) == null ? void 0 : _c[0]) == null ? void 0 : _d.v : formula1, formula2Result = isFormulaString(formula2) ? (_h = (_g = (_f = (_e = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _e.result) == null ? void 0 : _f[0]) == null ? void 0 : _g[0]) == null ? void 0 : _h.v : formula2, isFormulaValid = isLegalFormulaResult(`${formula1Result}`) && isLegalFormulaResult(`${formula2Result}`);
|
|
2476
640
|
return {
|
|
2477
|
-
formula1: this._parseNumber(
|
|
2478
|
-
formula2: this._parseNumber(
|
|
641
|
+
formula1: this._parseNumber(formula1Result),
|
|
642
|
+
formula2: this._parseNumber(formula2Result),
|
|
643
|
+
isFormulaValid
|
|
2479
644
|
};
|
|
2480
645
|
}
|
|
2481
646
|
validatorFormula(rule, unitId, subUnitId) {
|
|
@@ -2535,12 +700,12 @@ const _WholeValidator = class _WholeValidator extends BaseDataValidator {
|
|
|
2535
700
|
};
|
|
2536
701
|
__name(_WholeValidator, "WholeValidator");
|
|
2537
702
|
let WholeValidator = _WholeValidator;
|
|
2538
|
-
var __defProp$
|
|
2539
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
703
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
704
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2540
705
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2541
|
-
return kind && result && __defProp$
|
|
2542
|
-
}, "__decorateClass$
|
|
2543
|
-
let DataValidationController = (
|
|
706
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
707
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
|
|
708
|
+
let DataValidationController = (_a = class extends RxDisposable {
|
|
2544
709
|
constructor(_univerInstanceService, _dataValidatorRegistryService, _injector, _selectionManagerService, _sheetInterceptorService, _sheetDataValidationModel) {
|
|
2545
710
|
super(), this._univerInstanceService = _univerInstanceService, this._dataValidatorRegistryService = _dataValidatorRegistryService, this._injector = _injector, this._selectionManagerService = _selectionManagerService, this._sheetInterceptorService = _sheetInterceptorService, this._sheetDataValidationModel = _sheetDataValidationModel, this._init();
|
|
2546
711
|
}
|
|
@@ -2549,6 +714,7 @@ let DataValidationController = (_a6 = class extends RxDisposable {
|
|
|
2549
714
|
}
|
|
2550
715
|
_registerValidators() {
|
|
2551
716
|
[
|
|
717
|
+
AnyValidator,
|
|
2552
718
|
DecimalValidator,
|
|
2553
719
|
WholeValidator,
|
|
2554
720
|
TextLengthValidator,
|
|
@@ -2565,12 +731,12 @@ let DataValidationController = (_a6 = class extends RxDisposable {
|
|
|
2565
731
|
_initCommandInterceptor() {
|
|
2566
732
|
this._sheetInterceptorService.interceptCommand({
|
|
2567
733
|
getMutations: /* @__PURE__ */ __name((commandInfo) => {
|
|
2568
|
-
var
|
|
734
|
+
var _a6;
|
|
2569
735
|
if (commandInfo.id === ClearSelectionAllCommand.id) {
|
|
2570
736
|
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), worksheet = workbook.getActiveSheet();
|
|
2571
737
|
if (!worksheet)
|
|
2572
738
|
throw new Error("No active sheet found");
|
|
2573
|
-
const subUnitId = worksheet.getSheetId(), selections = (
|
|
739
|
+
const subUnitId = worksheet.getSheetId(), selections = (_a6 = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : _a6.map((s2) => s2.range), ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
2574
740
|
selections && ruleMatrix.removeRange(selections);
|
|
2575
741
|
const diffs = ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, this._injector, "patched");
|
|
2576
742
|
return {
|
|
@@ -2585,26 +751,26 @@ let DataValidationController = (_a6 = class extends RxDisposable {
|
|
|
2585
751
|
}, "getMutations")
|
|
2586
752
|
});
|
|
2587
753
|
}
|
|
2588
|
-
}, __name(
|
|
2589
|
-
DataValidationController = __decorateClass$
|
|
2590
|
-
__decorateParam$
|
|
2591
|
-
__decorateParam$
|
|
2592
|
-
__decorateParam$
|
|
2593
|
-
__decorateParam$
|
|
2594
|
-
__decorateParam$
|
|
2595
|
-
__decorateParam$
|
|
754
|
+
}, __name(_a, "DataValidationController"), _a);
|
|
755
|
+
DataValidationController = __decorateClass$4([
|
|
756
|
+
__decorateParam$4(0, IUniverInstanceService),
|
|
757
|
+
__decorateParam$4(1, Inject(DataValidatorRegistryService)),
|
|
758
|
+
__decorateParam$4(2, Inject(Injector)),
|
|
759
|
+
__decorateParam$4(3, Inject(SheetsSelectionsService)),
|
|
760
|
+
__decorateParam$4(4, Inject(SheetInterceptorService)),
|
|
761
|
+
__decorateParam$4(5, Inject(SheetDataValidationModel))
|
|
2596
762
|
], DataValidationController);
|
|
2597
|
-
var
|
|
2598
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
763
|
+
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$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
764
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2599
765
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2600
|
-
return kind && result && __defProp$
|
|
2601
|
-
}, "__decorateClass$
|
|
2602
|
-
let DataValidationFormulaController = (
|
|
766
|
+
return kind && result && __defProp$3(target, key, result), result;
|
|
767
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a2;
|
|
768
|
+
let DataValidationFormulaController = (_a2 = class extends Disposable {
|
|
2603
769
|
constructor(_univerInstanceService, _permissionService, _lexerTreeBuilder) {
|
|
2604
770
|
super(), this._univerInstanceService = _univerInstanceService, this._permissionService = _permissionService, this._lexerTreeBuilder = _lexerTreeBuilder;
|
|
2605
771
|
}
|
|
2606
772
|
getFormulaRefCheck(formulaString) {
|
|
2607
|
-
var
|
|
773
|
+
var _a6, _b;
|
|
2608
774
|
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
|
|
2609
775
|
if (!sequenceNodes)
|
|
2610
776
|
return !0;
|
|
@@ -2612,7 +778,7 @@ let DataValidationFormulaController = (_a7 = class extends Disposable {
|
|
|
2612
778
|
const node = sequenceNodes[i];
|
|
2613
779
|
if (typeof node == "string")
|
|
2614
780
|
continue;
|
|
2615
|
-
const { token } = node, sequenceGrid =
|
|
781
|
+
const { token } = node, sequenceGrid = deserializeRangeWithSheetWithCache(token), workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
2616
782
|
let targetSheet = workbook.getActiveSheet();
|
|
2617
783
|
const unitId = workbook.getUnitId();
|
|
2618
784
|
if (sequenceGrid.sheetName) {
|
|
@@ -2626,25 +792,25 @@ let DataValidationFormulaController = (_a7 = class extends Disposable {
|
|
|
2626
792
|
const { startRow, endRow, startColumn, endColumn } = sequenceGrid.range;
|
|
2627
793
|
for (let i2 = startRow; i2 <= endRow; i2++)
|
|
2628
794
|
for (let j = startColumn; j <= endColumn; j++) {
|
|
2629
|
-
const permission = (_b = (
|
|
2630
|
-
if ((permission == null ? void 0 : permission[
|
|
795
|
+
const permission = (_b = (_a6 = targetSheet.getCell(i2, j)) == null ? void 0 : _a6.selectionProtection) == null ? void 0 : _b[0];
|
|
796
|
+
if ((permission == null ? void 0 : permission[R.View]) === !1)
|
|
2631
797
|
return !1;
|
|
2632
798
|
}
|
|
2633
799
|
}
|
|
2634
800
|
return !0;
|
|
2635
801
|
}
|
|
2636
|
-
}, __name(
|
|
2637
|
-
DataValidationFormulaController = __decorateClass$
|
|
2638
|
-
__decorateParam$
|
|
2639
|
-
__decorateParam$
|
|
2640
|
-
__decorateParam$
|
|
802
|
+
}, __name(_a2, "DataValidationFormulaController"), _a2);
|
|
803
|
+
DataValidationFormulaController = __decorateClass$3([
|
|
804
|
+
__decorateParam$3(0, IUniverInstanceService),
|
|
805
|
+
__decorateParam$3(1, IPermissionService),
|
|
806
|
+
__decorateParam$3(2, Inject(LexerTreeBuilder))
|
|
2641
807
|
], DataValidationFormulaController);
|
|
2642
|
-
var __defProp$
|
|
2643
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
808
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
809
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2644
810
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2645
|
-
return kind && result && __defProp$
|
|
2646
|
-
}, "__decorateClass$
|
|
2647
|
-
let DataValidationRefRangeController = (
|
|
811
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
812
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
|
|
813
|
+
let DataValidationRefRangeController = (_a3 = class extends Disposable {
|
|
2648
814
|
constructor(_dataValidationModel, _injector, _refRangeService, _dataValidationCustomFormulaService, _dataValidationFormulaService, _formulaRefRangeService) {
|
|
2649
815
|
super();
|
|
2650
816
|
__publicField(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
@@ -2658,8 +824,8 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
|
|
|
2658
824
|
}
|
|
2659
825
|
// eslint-disable-next-line max-lines-per-function
|
|
2660
826
|
registerFormula(unitId, subUnitId, rule) {
|
|
2661
|
-
var
|
|
2662
|
-
const ruleId = rule.uid, id = this._getIdWithUnitId(unitId, subUnitId, ruleId), disposeSet = (
|
|
827
|
+
var _a6;
|
|
828
|
+
const ruleId = rule.uid, id = this._getIdWithUnitId(unitId, subUnitId, ruleId), disposeSet = (_a6 = this._disposableMap.get(id)) != null ? _a6 : /* @__PURE__ */ new Set(), handleFormulaChange = /* @__PURE__ */ __name((type, formulaString) => {
|
|
2663
829
|
const oldRule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
2664
830
|
if (!oldRule)
|
|
2665
831
|
return { redos: [], undos: [] };
|
|
@@ -2708,18 +874,21 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
|
|
|
2708
874
|
const currentFormula = this._dataValidationCustomFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
|
|
2709
875
|
if (currentFormula) {
|
|
2710
876
|
const disposable = this._formulaRefRangeService.registerFormula(
|
|
877
|
+
unitId,
|
|
878
|
+
subUnitId,
|
|
2711
879
|
currentFormula.formula,
|
|
2712
880
|
(newFormulaString) => handleFormulaChange("formula1", newFormulaString)
|
|
2713
881
|
);
|
|
2714
882
|
disposeSet.add(() => disposable.dispose());
|
|
2715
883
|
}
|
|
2716
|
-
}
|
|
2717
|
-
if (rule.type !== DataValidationType.CUSTOM) {
|
|
884
|
+
} else {
|
|
2718
885
|
const currentFormula = this._dataValidationFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
|
|
2719
886
|
if (currentFormula) {
|
|
2720
887
|
const [formula1, formula2] = currentFormula;
|
|
2721
888
|
if (formula1) {
|
|
2722
889
|
const disposable = this._formulaRefRangeService.registerFormula(
|
|
890
|
+
unitId,
|
|
891
|
+
subUnitId,
|
|
2723
892
|
formula1.text,
|
|
2724
893
|
(newFormulaString) => handleFormulaChange("formula1", newFormulaString)
|
|
2725
894
|
);
|
|
@@ -2727,6 +896,8 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
|
|
|
2727
896
|
}
|
|
2728
897
|
if (formula2) {
|
|
2729
898
|
const disposable = this._formulaRefRangeService.registerFormula(
|
|
899
|
+
unitId,
|
|
900
|
+
subUnitId,
|
|
2730
901
|
formula2.text,
|
|
2731
902
|
(newFormulaString) => handleFormulaChange("formula2", newFormulaString)
|
|
2732
903
|
);
|
|
@@ -2736,7 +907,7 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
|
|
|
2736
907
|
}
|
|
2737
908
|
}
|
|
2738
909
|
register(unitId, subUnitId, rule) {
|
|
2739
|
-
var
|
|
910
|
+
var _a6;
|
|
2740
911
|
const handleRangeChange = /* @__PURE__ */ __name((commandInfo) => {
|
|
2741
912
|
const oldRanges = [...rule.ranges], resultRanges = oldRanges.map((range) => handleCommonDefaultRangeChangeWithEffectRefCommands(range, commandInfo)).filter((range) => !!range).flat();
|
|
2742
913
|
if (isRangesEqual(resultRanges, oldRanges))
|
|
@@ -2774,7 +945,7 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
|
|
|
2774
945
|
const disposable = this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId);
|
|
2775
946
|
disposeList.push(() => disposable.dispose());
|
|
2776
947
|
});
|
|
2777
|
-
const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid), current = (
|
|
948
|
+
const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid), current = (_a6 = this._disposableMap.get(id)) != null ? _a6 : /* @__PURE__ */ new Set();
|
|
2778
949
|
current.add(() => disposeList.forEach((dispose) => dispose())), this._disposableMap.set(id, current);
|
|
2779
950
|
}
|
|
2780
951
|
_initRefRange() {
|
|
@@ -2810,21 +981,21 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
|
|
|
2810
981
|
}), this._disposableMap.clear();
|
|
2811
982
|
}));
|
|
2812
983
|
}
|
|
2813
|
-
}, __name(
|
|
2814
|
-
DataValidationRefRangeController = __decorateClass$
|
|
2815
|
-
__decorateParam$
|
|
2816
|
-
__decorateParam$
|
|
2817
|
-
__decorateParam$
|
|
2818
|
-
__decorateParam$
|
|
2819
|
-
__decorateParam$
|
|
2820
|
-
__decorateParam$
|
|
984
|
+
}, __name(_a3, "DataValidationRefRangeController"), _a3);
|
|
985
|
+
DataValidationRefRangeController = __decorateClass$2([
|
|
986
|
+
__decorateParam$2(0, Inject(SheetDataValidationModel)),
|
|
987
|
+
__decorateParam$2(1, Inject(Injector)),
|
|
988
|
+
__decorateParam$2(2, Inject(RefRangeService)),
|
|
989
|
+
__decorateParam$2(3, Inject(DataValidationCustomFormulaService)),
|
|
990
|
+
__decorateParam$2(4, Inject(DataValidationFormulaService)),
|
|
991
|
+
__decorateParam$2(5, Inject(FormulaRefRangeService))
|
|
2821
992
|
], DataValidationRefRangeController);
|
|
2822
|
-
var __defProp$
|
|
2823
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
993
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
994
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2824
995
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2825
|
-
return kind && result && __defProp$
|
|
2826
|
-
}, "__decorateClass$
|
|
2827
|
-
let SheetDataValidationSheetController = (
|
|
996
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
997
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a4;
|
|
998
|
+
let SheetDataValidationSheetController = (_a4 = class extends Disposable {
|
|
2828
999
|
constructor(_sheetInterceptorService, _univerInstanceService, _sheetDataValidationModel) {
|
|
2829
1000
|
super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._sheetDataValidationModel = _sheetDataValidationModel, this._initSheetChange();
|
|
2830
1001
|
}
|
|
@@ -2832,12 +1003,12 @@ let SheetDataValidationSheetController = (_a9 = class extends Disposable {
|
|
|
2832
1003
|
this.disposeWithMe(
|
|
2833
1004
|
this._sheetInterceptorService.interceptCommand({
|
|
2834
1005
|
getMutations: /* @__PURE__ */ __name((commandInfo) => {
|
|
2835
|
-
var
|
|
1006
|
+
var _a6;
|
|
2836
1007
|
if (commandInfo.id === RemoveSheetCommand.id) {
|
|
2837
1008
|
const params = commandInfo.params, unitId = params.unitId || this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId(), workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
|
|
2838
1009
|
if (!workbook)
|
|
2839
1010
|
return { redos: [], undos: [] };
|
|
2840
|
-
const subUnitId = params.subUnitId || ((
|
|
1011
|
+
const subUnitId = params.subUnitId || ((_a6 = workbook.getActiveSheet()) == null ? void 0 : _a6.getSheetId());
|
|
2841
1012
|
if (!subUnitId)
|
|
2842
1013
|
return { redos: [], undos: [] };
|
|
2843
1014
|
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
@@ -2870,104 +1041,18 @@ let SheetDataValidationSheetController = (_a9 = class extends Disposable {
|
|
|
2870
1041
|
})
|
|
2871
1042
|
);
|
|
2872
1043
|
}
|
|
2873
|
-
}, __name(
|
|
2874
|
-
SheetDataValidationSheetController = __decorateClass$
|
|
2875
|
-
__decorateParam$
|
|
2876
|
-
__decorateParam$
|
|
2877
|
-
__decorateParam$
|
|
1044
|
+
}, __name(_a4, "SheetDataValidationSheetController"), _a4);
|
|
1045
|
+
SheetDataValidationSheetController = __decorateClass$1([
|
|
1046
|
+
__decorateParam$1(0, Inject(SheetInterceptorService)),
|
|
1047
|
+
__decorateParam$1(1, Inject(IUniverInstanceService)),
|
|
1048
|
+
__decorateParam$1(2, Inject(SheetDataValidationModel))
|
|
2878
1049
|
], SheetDataValidationSheetController);
|
|
2879
|
-
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2880
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2881
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2882
|
-
return kind && result && __defProp$1(target, key, result), result;
|
|
2883
|
-
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a10;
|
|
2884
|
-
let SheetsDataValidationValidatorService = (_a10 = class extends Disposable {
|
|
2885
|
-
constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
|
|
2886
|
-
super(), this._univerInstanceService = _univerInstanceService, this._sheetDataValidationModel = _sheetDataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._lifecycleService = _lifecycleService, this._initRecalculate();
|
|
2887
|
-
}
|
|
2888
|
-
_initRecalculate() {
|
|
2889
|
-
const handleDirtyRanges = /* @__PURE__ */ __name((ranges) => {
|
|
2890
|
-
if (ranges.length === 0)
|
|
2891
|
-
return;
|
|
2892
|
-
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), worksheet = workbook == null ? void 0 : workbook.getActiveSheet(), map = {};
|
|
2893
|
-
ranges.flat().forEach((range) => {
|
|
2894
|
-
map[range.unitId] || (map[range.unitId] = {}), map[range.unitId][range.subUnitId] || (map[range.unitId][range.subUnitId] = []);
|
|
2895
|
-
const workbook2 = this._univerInstanceService.getUnit(range.unitId, UniverInstanceType.UNIVER_SHEET), worksheet2 = workbook2 == null ? void 0 : workbook2.getSheetBySheetId(range.subUnitId);
|
|
2896
|
-
worksheet2 && map[range.unitId][range.subUnitId].push(...range.ranges.map((range2) => Range.transformRange(range2, worksheet2)));
|
|
2897
|
-
}), Object.entries(map).forEach(([unitId, subUnitMap]) => {
|
|
2898
|
-
Object.entries(subUnitMap).forEach(([subUnitId, ranges2]) => {
|
|
2899
|
-
(workbook == null ? void 0 : workbook.getUnitId()) === unitId && (worksheet == null ? void 0 : worksheet.getSheetId()) === subUnitId ? this.validatorRanges(unitId, subUnitId, ranges2) : requestIdleCallback(() => {
|
|
2900
|
-
this.validatorRanges(unitId, subUnitId, ranges2);
|
|
2901
|
-
});
|
|
2902
|
-
});
|
|
2903
|
-
});
|
|
2904
|
-
}, "handleDirtyRanges");
|
|
2905
|
-
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));
|
|
2906
|
-
}
|
|
2907
|
-
async validatorCell(unitId, subUnitId, row, col) {
|
|
2908
|
-
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
2909
|
-
if (!workbook)
|
|
2910
|
-
throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
2911
|
-
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
2912
|
-
if (!worksheet)
|
|
2913
|
-
throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
2914
|
-
if (!Tools.isDefine(row) || !Tools.isDefine(col))
|
|
2915
|
-
throw new Error(`row or col is not defined, row: ${row}, col: ${col}`);
|
|
2916
|
-
const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
|
|
2917
|
-
return rule ? new Promise((resolve) => {
|
|
2918
|
-
this._sheetDataValidationModel.validator(rule, { unitId, subUnitId, row, col, worksheet, workbook }, (status) => {
|
|
2919
|
-
resolve(status);
|
|
2920
|
-
});
|
|
2921
|
-
}) : DataValidationStatus.VALID;
|
|
2922
|
-
}
|
|
2923
|
-
validatorRanges(unitId, subUnitId, ranges) {
|
|
2924
|
-
return Promise.all(ranges.map((range) => {
|
|
2925
|
-
const promises = [];
|
|
2926
|
-
return Range.foreach(range, (row, col) => {
|
|
2927
|
-
promises.push(this.validatorCell(unitId, subUnitId, row, col));
|
|
2928
|
-
}), promises;
|
|
2929
|
-
}));
|
|
2930
|
-
}
|
|
2931
|
-
async validatorWorksheet(unitId, subUnitId) {
|
|
2932
|
-
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
2933
|
-
return await Promise.all(rules.map((rule) => Promise.all(rule.ranges.map((range) => {
|
|
2934
|
-
const promises = [];
|
|
2935
|
-
return Range.foreach(range, (row, col) => {
|
|
2936
|
-
promises.push(this.validatorCell(unitId, subUnitId, row, col));
|
|
2937
|
-
}), promises;
|
|
2938
|
-
})))), this._dataValidationCacheService.ensureCache(unitId, subUnitId);
|
|
2939
|
-
}
|
|
2940
|
-
async validatorWorkbook(unitId) {
|
|
2941
|
-
const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId), results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id))), map = {};
|
|
2942
|
-
return results.forEach((result, i) => {
|
|
2943
|
-
map[sheetIds[i]] = result;
|
|
2944
|
-
}), map;
|
|
2945
|
-
}
|
|
2946
|
-
getDataValidations(unitId, subUnitId, ranges) {
|
|
2947
|
-
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId), ruleIdSet = /* @__PURE__ */ new Set();
|
|
2948
|
-
return ranges.forEach((range) => {
|
|
2949
|
-
Range.foreach(range, (row, col) => {
|
|
2950
|
-
const ruleId = ruleMatrix.getValue(row, col);
|
|
2951
|
-
ruleId && ruleIdSet.add(ruleId);
|
|
2952
|
-
});
|
|
2953
|
-
}), Array.from(ruleIdSet).map((id) => this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
2954
|
-
}
|
|
2955
|
-
getDataValidation(unitId, subUnitId, ranges) {
|
|
2956
|
-
return this.getDataValidations(unitId, subUnitId, ranges)[0];
|
|
2957
|
-
}
|
|
2958
|
-
}, __name(_a10, "SheetsDataValidationValidatorService"), _a10);
|
|
2959
|
-
SheetsDataValidationValidatorService = __decorateClass$1([
|
|
2960
|
-
__decorateParam$1(0, IUniverInstanceService),
|
|
2961
|
-
__decorateParam$1(1, Inject(SheetDataValidationModel)),
|
|
2962
|
-
__decorateParam$1(2, Inject(DataValidationCacheService)),
|
|
2963
|
-
__decorateParam$1(3, Inject(LifecycleService))
|
|
2964
|
-
], SheetsDataValidationValidatorService);
|
|
2965
1050
|
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) => {
|
|
2966
1051
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2967
1052
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2968
1053
|
return kind && result && __defProp2(target, key, result), result;
|
|
2969
|
-
}, "__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"),
|
|
2970
|
-
let UniverSheetsDataValidationPlugin = (
|
|
1054
|
+
}, "__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"), _a5;
|
|
1055
|
+
let UniverSheetsDataValidationPlugin = (_a5 = class extends Plugin {
|
|
2971
1056
|
constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
|
|
2972
1057
|
super(), this._config = _config, this._injector = _injector, this._commandService = _commandService, this._configService = _configService;
|
|
2973
1058
|
const { ...rest } = this._config;
|
|
@@ -3004,7 +1089,7 @@ let UniverSheetsDataValidationPlugin = (_a11 = class extends Plugin {
|
|
|
3004
1089
|
onRendered() {
|
|
3005
1090
|
this._injector.get(DataValidationController), this._injector.get(DataValidationFormulaController);
|
|
3006
1091
|
}
|
|
3007
|
-
}, __name(
|
|
1092
|
+
}, __name(_a5, "UniverSheetsDataValidationPlugin"), _a5);
|
|
3008
1093
|
__publicField2(UniverSheetsDataValidationPlugin, "pluginName", DATA_VALIDATION_PLUGIN_NAME);
|
|
3009
1094
|
__publicField2(UniverSheetsDataValidationPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
3010
1095
|
UniverSheetsDataValidationPlugin = __decorateClass([
|
|
@@ -3014,7 +1099,7 @@ UniverSheetsDataValidationPlugin = __decorateClass([
|
|
|
3014
1099
|
__decorateParam(3, IConfigService)
|
|
3015
1100
|
], UniverSheetsDataValidationPlugin);
|
|
3016
1101
|
function createDefaultNewRule(accessor) {
|
|
3017
|
-
const currentRanges = accessor.get(SheetsSelectionsService).getCurrentSelections().map((
|
|
1102
|
+
const currentRanges = accessor.get(SheetsSelectionsService).getCurrentSelections().map((s2) => s2.range);
|
|
3018
1103
|
return {
|
|
3019
1104
|
uid: Tools.generateRandomId(6),
|
|
3020
1105
|
type: DataValidationType.DECIMAL,
|
|
@@ -3026,8 +1111,8 @@ function createDefaultNewRule(accessor) {
|
|
|
3026
1111
|
__name(createDefaultNewRule, "createDefaultNewRule");
|
|
3027
1112
|
export {
|
|
3028
1113
|
AddSheetDataValidationCommand,
|
|
3029
|
-
CHECKBOX_FORMULA_1,
|
|
3030
|
-
CHECKBOX_FORMULA_2,
|
|
1114
|
+
q as CHECKBOX_FORMULA_1,
|
|
1115
|
+
s as CHECKBOX_FORMULA_2,
|
|
3031
1116
|
CheckboxValidator,
|
|
3032
1117
|
ClearRangeDataValidationCommand,
|
|
3033
1118
|
DATA_VALIDATION_PLUGIN_NAME,
|
|
@@ -3053,6 +1138,7 @@ export {
|
|
|
3053
1138
|
getDataValidationDiffMutations,
|
|
3054
1139
|
getFormulaCellData,
|
|
3055
1140
|
getFormulaResult,
|
|
1141
|
+
isLegalFormulaResult,
|
|
3056
1142
|
serializeListOptions,
|
|
3057
|
-
transformCheckboxValue
|
|
1143
|
+
t as transformCheckboxValue
|
|
3058
1144
|
};
|