@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
|
@@ -0,0 +1,2032 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { Inject, ICommandService, Disposable, ObjectMatrix, Range, Injector, UniverInstanceType, DataValidationType, isFormulaString, IUniverInstanceService, getOriginCellValue, debounce, Rectangle, Tools, DataValidationStatus, WrapStrategy, DataValidationOperator, CommandType, IUndoRedoService, sequenceExecute, LifecycleService, LifecycleStages, bufferDebounceTime } from "@univerjs/core";
|
|
6
|
+
import { DataValidationModel, DataValidatorRegistryService, UpdateRuleType, BaseDataValidator, AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation, getRuleSetting, getRuleOptions } from "@univerjs/data-validation";
|
|
7
|
+
import { LexerTreeBuilder, ERROR_TYPE_SET } from "@univerjs/engine-formula";
|
|
8
|
+
import { SetRangeValuesMutation, RemoveSheetMutation, getSheetCommandTarget, SetRangeValuesUndoMutationFactory } from "@univerjs/sheets";
|
|
9
|
+
import { Subject, bufferWhen, filter } from "rxjs";
|
|
10
|
+
import { RegisterOtherFormulaService } from "@univerjs/sheets-formula";
|
|
11
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
12
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
13
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
14
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
15
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
|
|
16
|
+
let DataValidationCacheService = (_a = class extends Disposable {
|
|
17
|
+
constructor(_commandService) {
|
|
18
|
+
super();
|
|
19
|
+
__publicField(this, "_cacheMatrix", /* @__PURE__ */ new Map());
|
|
20
|
+
__publicField(this, "_dirtyRanges$", new Subject());
|
|
21
|
+
__publicField(this, "dirtyRanges$", this._dirtyRanges$.asObservable());
|
|
22
|
+
this._commandService = _commandService, this._initDirtyRanges();
|
|
23
|
+
}
|
|
24
|
+
_initDirtyRanges() {
|
|
25
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
26
|
+
if (commandInfo.id === SetRangeValuesMutation.id) {
|
|
27
|
+
const { cellValue, unitId, subUnitId } = commandInfo.params;
|
|
28
|
+
if (cellValue) {
|
|
29
|
+
const range = new ObjectMatrix(cellValue).getDataRange();
|
|
30
|
+
if (range.endRow === -1) return;
|
|
31
|
+
this._dirtyRanges$.next({
|
|
32
|
+
unitId,
|
|
33
|
+
subUnitId,
|
|
34
|
+
ranges: [range]
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
_ensureCache(unitId, subUnitId) {
|
|
41
|
+
let unitMap = this._cacheMatrix.get(unitId);
|
|
42
|
+
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._cacheMatrix.set(unitId, unitMap));
|
|
43
|
+
let cacheMatrix = unitMap.get(subUnitId);
|
|
44
|
+
return cacheMatrix || (cacheMatrix = new ObjectMatrix(), unitMap.set(subUnitId, cacheMatrix)), cacheMatrix;
|
|
45
|
+
}
|
|
46
|
+
ensureCache(unitId, subUnitId) {
|
|
47
|
+
return this._ensureCache(unitId, subUnitId);
|
|
48
|
+
}
|
|
49
|
+
addRule(unitId, subUnitId, rule) {
|
|
50
|
+
this.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
51
|
+
}
|
|
52
|
+
removeRule(unitId, subUnitId, rule) {
|
|
53
|
+
this._deleteRange(unitId, subUnitId, rule.ranges);
|
|
54
|
+
}
|
|
55
|
+
updateRuleRanges(unitId, subUnitId, ruleId, newRanges, oldRanges) {
|
|
56
|
+
const cache = this._ensureCache(unitId, subUnitId);
|
|
57
|
+
oldRanges.forEach((range) => {
|
|
58
|
+
Range.foreach(range, (row, col) => {
|
|
59
|
+
const item = cache.getValue(row, col);
|
|
60
|
+
item && (item.temp = !0);
|
|
61
|
+
});
|
|
62
|
+
}), newRanges.forEach((range) => {
|
|
63
|
+
Range.foreach(range, (row, col) => {
|
|
64
|
+
const item = cache.getValue(row, col);
|
|
65
|
+
item && item.ruleId === ruleId ? item.temp = !1 : cache.setValue(row, col, void 0);
|
|
66
|
+
});
|
|
67
|
+
}), oldRanges.forEach((range) => {
|
|
68
|
+
Range.foreach(range, (row, col) => {
|
|
69
|
+
const item = cache.getValue(row, col);
|
|
70
|
+
item && item.temp === !0 && cache.realDeleteValue(row, col);
|
|
71
|
+
});
|
|
72
|
+
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges: [...oldRanges, ...newRanges] });
|
|
73
|
+
}
|
|
74
|
+
markRangeDirty(unitId, subUnitId, ranges) {
|
|
75
|
+
const cache = this._ensureCache(unitId, subUnitId);
|
|
76
|
+
ranges.forEach((range) => {
|
|
77
|
+
Range.foreach(range, (row, col) => {
|
|
78
|
+
cache.setValue(row, col, void 0);
|
|
79
|
+
});
|
|
80
|
+
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
|
|
81
|
+
}
|
|
82
|
+
markCellDirty(unitId, subUnitId, row, col) {
|
|
83
|
+
this._ensureCache(unitId, subUnitId).setValue(row, col, void 0), this._dirtyRanges$.next({ unitId, subUnitId, ranges: [{ startRow: row, startColumn: col, endRow: row, endColumn: col }] });
|
|
84
|
+
}
|
|
85
|
+
_deleteRange(unitId, subUnitId, ranges) {
|
|
86
|
+
const cache = this._ensureCache(unitId, subUnitId);
|
|
87
|
+
ranges.forEach((range) => {
|
|
88
|
+
Range.foreach(range, (row, col) => {
|
|
89
|
+
cache.realDeleteValue(row, col);
|
|
90
|
+
});
|
|
91
|
+
}), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
|
|
92
|
+
}
|
|
93
|
+
getValue(unitId, subUnitId, row, col) {
|
|
94
|
+
return this._ensureCache(unitId, subUnitId).getValue(row, col);
|
|
95
|
+
}
|
|
96
|
+
setValue(unitId, subUnitId, row, col, value) {
|
|
97
|
+
return this._ensureCache(unitId, subUnitId).setValue(row, col, value);
|
|
98
|
+
}
|
|
99
|
+
}, __name(_a, "DataValidationCacheService"), _a);
|
|
100
|
+
DataValidationCacheService = __decorateClass$4([
|
|
101
|
+
__decorateParam$4(0, Inject(ICommandService))
|
|
102
|
+
], DataValidationCacheService);
|
|
103
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
104
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
105
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
106
|
+
return kind && result && __defProp$3(target, key, result), result;
|
|
107
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3");
|
|
108
|
+
function transformFormula(lexerTreeBuilder, formula, originRow, originCol, targetRow, targetCol) {
|
|
109
|
+
return lexerTreeBuilder.moveFormulaRefOffset(formula, targetCol - originCol, targetRow - originRow);
|
|
110
|
+
}
|
|
111
|
+
__name(transformFormula, "transformFormula");
|
|
112
|
+
var _a2;
|
|
113
|
+
let DataValidationCustomFormulaService = (_a2 = class extends Disposable {
|
|
114
|
+
constructor(_instanceSrv, _registerOtherFormulaService, _lexerTreeBuilder, _dataValidationModel, _dataValidationCacheService, _injector) {
|
|
115
|
+
super();
|
|
116
|
+
__publicField(this, "_formulaMap", /* @__PURE__ */ new Map());
|
|
117
|
+
/**
|
|
118
|
+
* Map of origin formula of rule
|
|
119
|
+
*/
|
|
120
|
+
__publicField(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
|
|
121
|
+
/**
|
|
122
|
+
* reflect of formulaId to cell, only store transformable formula
|
|
123
|
+
*/
|
|
124
|
+
__publicField(this, "_formulaCellMap", /* @__PURE__ */ new Map());
|
|
125
|
+
this._instanceSrv = _instanceSrv, this._registerOtherFormulaService = _registerOtherFormulaService, this._lexerTreeBuilder = _lexerTreeBuilder, this._dataValidationModel = _dataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._injector = _injector, this._initFormulaResultHandler();
|
|
126
|
+
}
|
|
127
|
+
_initFormulaResultHandler() {
|
|
128
|
+
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
129
|
+
for (const unitId in resultMap) {
|
|
130
|
+
const unitMap = resultMap[unitId];
|
|
131
|
+
if (this._instanceSrv.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
|
|
132
|
+
for (const subUnitId in unitMap) {
|
|
133
|
+
const results = unitMap[subUnitId], { formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
134
|
+
results.forEach((result) => {
|
|
135
|
+
var _a7, _b;
|
|
136
|
+
const ruleInfo = ruleFormulaMap.get((_a7 = result.extra) == null ? void 0 : _a7.ruleId), cellInfo = formulaCellMap.get(result.formulaId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
|
|
137
|
+
rule && ruleInfo && !ruleInfo.isTransformable && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges), cellInfo && this._dataValidationCacheService.markCellDirty(unitId, subUnitId, cellInfo.row, cellInfo.column);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
_ensureMaps(unitId, subUnitId) {
|
|
144
|
+
let formulaUnitMap = this._formulaMap.get(unitId), ruleFormulaUnitMap = this._ruleFormulaMap.get(unitId), formulaCellUnitMap = this._formulaCellMap.get(unitId);
|
|
145
|
+
(!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));
|
|
146
|
+
let formulaMap = formulaUnitMap.get(subUnitId), ruleFormulaMap = ruleFormulaUnitMap.get(subUnitId), formulaCellMap = formulaCellUnitMap.get(subUnitId);
|
|
147
|
+
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)), {
|
|
148
|
+
formulaMap,
|
|
149
|
+
ruleFormulaMap,
|
|
150
|
+
formulaCellMap
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
_registerFormula(unitId, subUnitId, ruleId, formulaString) {
|
|
154
|
+
return this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formulaString, { ruleId });
|
|
155
|
+
}
|
|
156
|
+
deleteByRuleId(unitId, subUnitId, ruleId) {
|
|
157
|
+
const { formulaMap, formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId), formulaIdList = /* @__PURE__ */ new Set(), formulaInfo = ruleFormulaMap.get(ruleId);
|
|
158
|
+
!rule || !formulaInfo || (ruleFormulaMap.delete(ruleId), rule.ranges.forEach((range) => {
|
|
159
|
+
Range.foreach(range, (row, col) => {
|
|
160
|
+
const value = formulaMap.getValue(row, col);
|
|
161
|
+
if (value && value.ruleId === ruleId) {
|
|
162
|
+
const { formulaId } = value;
|
|
163
|
+
formulaMap.realDeleteValue(row, col), formulaIdList.add(formulaId), formulaCellMap.delete(formulaId);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, Array.from(formulaIdList.values())));
|
|
167
|
+
}
|
|
168
|
+
_addFormulaByRange(unitId, subUnitId, ruleId, formula, ranges) {
|
|
169
|
+
const { formulaMap, ruleFormulaMap, formulaCellMap } = this._ensureMaps(unitId, subUnitId);
|
|
170
|
+
if (!formula)
|
|
171
|
+
return;
|
|
172
|
+
const originRow = ranges[0].startRow, originCol = ranges[0].startColumn;
|
|
173
|
+
let originFormulaId;
|
|
174
|
+
ranges.forEach((range) => {
|
|
175
|
+
Range.foreach(range, (row, column) => {
|
|
176
|
+
const relativeFormula = transformFormula(
|
|
177
|
+
this._lexerTreeBuilder,
|
|
178
|
+
formula,
|
|
179
|
+
originRow,
|
|
180
|
+
originCol,
|
|
181
|
+
row,
|
|
182
|
+
column
|
|
183
|
+
), formulaId = this._registerFormula(unitId, subUnitId, ruleId, relativeFormula);
|
|
184
|
+
formulaMap.setValue(row, column, {
|
|
185
|
+
formulaId,
|
|
186
|
+
// formulaText: relativeFormula,
|
|
187
|
+
ruleId
|
|
188
|
+
}), formulaCellMap.set(formulaId, { row, column });
|
|
189
|
+
});
|
|
190
|
+
}), ruleFormulaMap.set(ruleId, {
|
|
191
|
+
formula,
|
|
192
|
+
originCol,
|
|
193
|
+
originRow,
|
|
194
|
+
formulaId: originFormulaId,
|
|
195
|
+
isTransformable: !0
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
addRule(unitId, subUnitId, rule) {
|
|
199
|
+
const { ranges, formula1, uid: ruleId, type } = rule;
|
|
200
|
+
type !== DataValidationType.CUSTOM || !formula1 || !isFormulaString(formula1) || this._addFormulaByRange(unitId, subUnitId, ruleId, formula1, ranges);
|
|
201
|
+
}
|
|
202
|
+
updateRuleRanges(unitId, subUnitId, ruleId, oldRanges, newRanges) {
|
|
203
|
+
const { formulaMap, ruleFormulaMap, formulaCellMap } = this._ensureMaps(unitId, subUnitId), info = ruleFormulaMap.get(ruleId);
|
|
204
|
+
if (!info)
|
|
205
|
+
return;
|
|
206
|
+
const { formula, originCol, originRow, isTransformable, formulaId } = info, deleteFormulaIdList = /* @__PURE__ */ new Set();
|
|
207
|
+
oldRanges.forEach((range) => {
|
|
208
|
+
Range.foreach(range, (row, col) => {
|
|
209
|
+
const value = formulaMap.getValue(row, col);
|
|
210
|
+
value && value.ruleId === ruleId && (value.temp = !0);
|
|
211
|
+
});
|
|
212
|
+
}), newRanges.forEach((range) => {
|
|
213
|
+
Range.foreach(range, (row, col) => {
|
|
214
|
+
var _a7;
|
|
215
|
+
const oldValue = (_a7 = formulaMap.getValue(row, col)) != null ? _a7 : {};
|
|
216
|
+
if (oldValue.ruleId !== ruleId) {
|
|
217
|
+
const oldRuleFormula = ruleFormulaMap.get(oldValue.ruleId);
|
|
218
|
+
if (oldRuleFormula != null && oldRuleFormula.isTransformable && deleteFormulaIdList.add(oldValue.formulaId), isTransformable) {
|
|
219
|
+
const relativeText = transformFormula(this._lexerTreeBuilder, formula, originRow, originCol, row, col), formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, relativeText);
|
|
220
|
+
formulaMap.setValue(row, col, {
|
|
221
|
+
ruleId,
|
|
222
|
+
formulaId: formulaId2
|
|
223
|
+
}), formulaCellMap.set(formulaId2, { row, column: col });
|
|
224
|
+
} else
|
|
225
|
+
formulaMap.setValue(row, col, {
|
|
226
|
+
// formulaText: formula,
|
|
227
|
+
ruleId,
|
|
228
|
+
formulaId
|
|
229
|
+
});
|
|
230
|
+
} else
|
|
231
|
+
oldValue.temp = !1;
|
|
232
|
+
});
|
|
233
|
+
}), oldRanges.forEach((range) => {
|
|
234
|
+
Range.foreach(range, (row, col) => {
|
|
235
|
+
const value = formulaMap.getValue(row, col);
|
|
236
|
+
value && value.ruleId === ruleId && value.temp === !0 && (formulaMap.realDeleteValue(row, col), isTransformable && deleteFormulaIdList.add(value.formulaId));
|
|
237
|
+
});
|
|
238
|
+
}), deleteFormulaIdList.forEach((formulaId2) => {
|
|
239
|
+
formulaCellMap.delete(formulaId2);
|
|
240
|
+
}), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, Array.from(deleteFormulaIdList.values()));
|
|
241
|
+
}
|
|
242
|
+
updateRuleFormula(unitId, subUnitId, ruleId, ranges, formula) {
|
|
243
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap.get(ruleId);
|
|
244
|
+
(!current || current.formula !== formula) && this._addFormulaByRange(unitId, subUnitId, ruleId, formula, ranges);
|
|
245
|
+
}
|
|
246
|
+
getCellFormulaValue(unitId, subUnitId, row, col) {
|
|
247
|
+
const { formulaMap } = this._ensureMaps(unitId, subUnitId), current = formulaMap.getValue(row, col);
|
|
248
|
+
return current ? this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId) : Promise.resolve(void 0);
|
|
249
|
+
}
|
|
250
|
+
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
251
|
+
const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
|
|
252
|
+
return ruleFormulaMap.get(ruleId);
|
|
253
|
+
}
|
|
254
|
+
}, __name(_a2, "DataValidationCustomFormulaService"), _a2);
|
|
255
|
+
DataValidationCustomFormulaService = __decorateClass$3([
|
|
256
|
+
__decorateParam$3(0, IUniverInstanceService),
|
|
257
|
+
__decorateParam$3(1, Inject(RegisterOtherFormulaService)),
|
|
258
|
+
__decorateParam$3(2, Inject(LexerTreeBuilder)),
|
|
259
|
+
__decorateParam$3(3, Inject(DataValidationModel)),
|
|
260
|
+
__decorateParam$3(4, Inject(DataValidationCacheService)),
|
|
261
|
+
__decorateParam$3(5, Inject(Injector))
|
|
262
|
+
], DataValidationCustomFormulaService);
|
|
263
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
264
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
265
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
266
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
267
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
|
|
268
|
+
let DataValidationFormulaService = (_a3 = class extends Disposable {
|
|
269
|
+
constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel) {
|
|
270
|
+
super();
|
|
271
|
+
__publicField(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
|
|
272
|
+
this._instanceService = _instanceService, this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationModel = _dataValidationModel, this._initFormulaResultHandler();
|
|
273
|
+
}
|
|
274
|
+
_initFormulaResultHandler() {
|
|
275
|
+
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
|
|
276
|
+
for (const unitId in resultMap) {
|
|
277
|
+
const unitMap = resultMap[unitId];
|
|
278
|
+
if (this._instanceService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
|
|
279
|
+
for (const subUnitId in unitMap) {
|
|
280
|
+
const results = unitMap[subUnitId], formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
|
|
281
|
+
results.forEach((result) => {
|
|
282
|
+
var _a7, _b;
|
|
283
|
+
if (formulaMap.get((_a7 = result.extra) == null ? void 0 : _a7.ruleId)) {
|
|
284
|
+
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
|
|
285
|
+
rule && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
_ensureRuleFormulaMap(unitId, subUnitId) {
|
|
293
|
+
let unitMap = this._formulaRuleMap.get(unitId);
|
|
294
|
+
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._formulaRuleMap.set(unitId, unitMap));
|
|
295
|
+
let subUnitMap = unitMap.get(subUnitId);
|
|
296
|
+
return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
|
|
297
|
+
}
|
|
298
|
+
addRule(unitId, subUnitId, ruleId, formula1, formula2) {
|
|
299
|
+
const isFormula1Legal = isFormulaString(formula1), isFormula2Legal = isFormulaString(formula2);
|
|
300
|
+
if (!isFormula1Legal && !isFormula2Legal)
|
|
301
|
+
return;
|
|
302
|
+
const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId), item = [void 0, void 0];
|
|
303
|
+
if (isFormula1Legal) {
|
|
304
|
+
const id = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula1, { ruleId });
|
|
305
|
+
item[0] = { id, text: formula1 };
|
|
306
|
+
}
|
|
307
|
+
if (isFormula2Legal) {
|
|
308
|
+
const id = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula2, { ruleId });
|
|
309
|
+
item[1] = { id, text: formula2 };
|
|
310
|
+
}
|
|
311
|
+
formulaRuleMap.set(ruleId, item);
|
|
312
|
+
}
|
|
313
|
+
removeRule(unitId, subUnitId, ruleId) {
|
|
314
|
+
const item = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
315
|
+
if (!item)
|
|
316
|
+
return;
|
|
317
|
+
const [formula1, formula2] = item, idList = [formula1 == null ? void 0 : formula1.id, formula2 == null ? void 0 : formula2.id].filter(Boolean);
|
|
318
|
+
idList.length && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, idList);
|
|
319
|
+
}
|
|
320
|
+
updateRuleFormulaText(unitId, subUnitId, ruleId, formula1, formula2) {
|
|
321
|
+
const item = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
322
|
+
if (!item) {
|
|
323
|
+
this.addRule(unitId, subUnitId, ruleId, formula1, formula2);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const [oldFormula1, oldFormula2] = item;
|
|
327
|
+
if ((oldFormula1 == null ? void 0 : oldFormula1.text) !== formula1)
|
|
328
|
+
if (oldFormula1 && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [oldFormula1.id]), isFormulaString(formula1)) {
|
|
329
|
+
const formulaId = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula1, { ruleId });
|
|
330
|
+
item[0] = {
|
|
331
|
+
text: formula1,
|
|
332
|
+
id: formulaId
|
|
333
|
+
};
|
|
334
|
+
} else
|
|
335
|
+
item[0] = void 0;
|
|
336
|
+
if ((oldFormula2 == null ? void 0 : oldFormula2.text) !== formula2)
|
|
337
|
+
if (oldFormula2 && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [oldFormula2.id]), isFormulaString(formula2)) {
|
|
338
|
+
const formulaId = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, formula2, { ruleId });
|
|
339
|
+
item[1] = {
|
|
340
|
+
text: formula2,
|
|
341
|
+
id: formulaId
|
|
342
|
+
};
|
|
343
|
+
} else
|
|
344
|
+
item[1] = void 0;
|
|
345
|
+
}
|
|
346
|
+
getRuleFormulaResult(unitId, subUnitId, ruleId) {
|
|
347
|
+
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
348
|
+
if (!formulaInfo)
|
|
349
|
+
return Promise.resolve(null);
|
|
350
|
+
const getResult = /* @__PURE__ */ __name(async (info) => info && this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, info.id), "getResult");
|
|
351
|
+
return Promise.all([
|
|
352
|
+
getResult(formulaInfo[0]),
|
|
353
|
+
getResult(formulaInfo[1])
|
|
354
|
+
]);
|
|
355
|
+
}
|
|
356
|
+
getRuleFormulaResultSync(unitId, subUnitId, ruleId) {
|
|
357
|
+
const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
358
|
+
if (formulaInfo)
|
|
359
|
+
return formulaInfo.map((i) => {
|
|
360
|
+
if (i)
|
|
361
|
+
return this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, i.id);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
getRuleFormulaInfo(unitId, subUnitId, ruleId) {
|
|
365
|
+
return this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
|
|
366
|
+
}
|
|
367
|
+
}, __name(_a3, "DataValidationFormulaService"), _a3);
|
|
368
|
+
DataValidationFormulaService = __decorateClass$2([
|
|
369
|
+
__decorateParam$2(0, IUniverInstanceService),
|
|
370
|
+
__decorateParam$2(1, Inject(RegisterOtherFormulaService)),
|
|
371
|
+
__decorateParam$2(2, Inject(DataValidationCacheService)),
|
|
372
|
+
__decorateParam$2(3, Inject(DataValidationModel))
|
|
373
|
+
], DataValidationFormulaService);
|
|
374
|
+
function getCellValueOrigin(cell) {
|
|
375
|
+
return getOriginCellValue(cell);
|
|
376
|
+
}
|
|
377
|
+
__name(getCellValueOrigin, "getCellValueOrigin");
|
|
378
|
+
function getStringCellValue(cell) {
|
|
379
|
+
var _a7;
|
|
380
|
+
return String((_a7 = getCellValueOrigin(cell)) != null ? _a7 : "");
|
|
381
|
+
}
|
|
382
|
+
__name(getStringCellValue, "getStringCellValue");
|
|
383
|
+
var _a4;
|
|
384
|
+
const Interval = (_a4 = class {
|
|
385
|
+
/**
|
|
386
|
+
* Accept two comparable values and creates new instance of interval
|
|
387
|
+
* Predicate Interval.comparable_less(low, high) supposed to return true on these values
|
|
388
|
+
* @param low
|
|
389
|
+
* @param high
|
|
390
|
+
*/
|
|
391
|
+
constructor(low, high) {
|
|
392
|
+
this.low = low, this.high = high;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Clone interval
|
|
396
|
+
* @returns {Interval}
|
|
397
|
+
*/
|
|
398
|
+
clone() {
|
|
399
|
+
return new _a4(this.low, this.high);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Propery max returns clone of this interval
|
|
403
|
+
* @returns {Interval}
|
|
404
|
+
*/
|
|
405
|
+
get max() {
|
|
406
|
+
return this.clone();
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Predicate returns true is this interval less than other interval
|
|
410
|
+
* @param other_interval
|
|
411
|
+
* @returns {boolean}
|
|
412
|
+
*/
|
|
413
|
+
less_than(other_interval) {
|
|
414
|
+
return this.low < other_interval.low || this.low === other_interval.low && this.high < other_interval.high;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Predicate returns true is this interval equals to other interval
|
|
418
|
+
* @param other_interval
|
|
419
|
+
* @returns {boolean}
|
|
420
|
+
*/
|
|
421
|
+
equal_to(other_interval) {
|
|
422
|
+
return this.low === other_interval.low && this.high === other_interval.high;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Predicate returns true if this interval intersects other interval
|
|
426
|
+
* @param other_interval
|
|
427
|
+
* @returns {boolean}
|
|
428
|
+
*/
|
|
429
|
+
intersect(other_interval) {
|
|
430
|
+
return !this.not_intersect(other_interval);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Predicate returns true if this interval does not intersect other interval
|
|
434
|
+
* @param other_interval
|
|
435
|
+
* @returns {boolean}
|
|
436
|
+
*/
|
|
437
|
+
not_intersect(other_interval) {
|
|
438
|
+
return this.high < other_interval.low || other_interval.high < this.low;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Returns new interval merged with other interval
|
|
442
|
+
* @param {Interval} other_interval - Other interval to merge with
|
|
443
|
+
* @returns {Interval}
|
|
444
|
+
*/
|
|
445
|
+
merge(other_interval) {
|
|
446
|
+
return new _a4(
|
|
447
|
+
this.low === void 0 ? other_interval.low : this.low < other_interval.low ? this.low : other_interval.low,
|
|
448
|
+
this.high === void 0 ? other_interval.high : this.high > other_interval.high ? this.high : other_interval.high
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Returns how key should return
|
|
453
|
+
*/
|
|
454
|
+
output() {
|
|
455
|
+
return [this.low, this.high];
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Function returns maximum between two comparable values
|
|
459
|
+
* @param interval1
|
|
460
|
+
* @param interval2
|
|
461
|
+
* @returns {Interval}
|
|
462
|
+
*/
|
|
463
|
+
static comparable_max(interval1, interval2) {
|
|
464
|
+
return interval1.merge(interval2);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Predicate returns true if first value less than second value
|
|
468
|
+
* @param val1
|
|
469
|
+
* @param val2
|
|
470
|
+
* @returns {boolean}
|
|
471
|
+
*/
|
|
472
|
+
static comparable_less_than(val1, val2) {
|
|
473
|
+
return val1 < val2;
|
|
474
|
+
}
|
|
475
|
+
}, __name(_a4, "Interval"), _a4), RB_TREE_COLOR_RED = 0, RB_TREE_COLOR_BLACK = 1, _Node = class _Node {
|
|
476
|
+
constructor(key = void 0, value = void 0, left = null, right = null, parent = null, color = RB_TREE_COLOR_BLACK) {
|
|
477
|
+
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])) {
|
|
478
|
+
let [low, high] = key;
|
|
479
|
+
low > high && ([low, high] = [high, low]), this.item.key = new Interval(low, high);
|
|
480
|
+
}
|
|
481
|
+
this.max = this.item.key ? this.item.key.max : void 0;
|
|
482
|
+
}
|
|
483
|
+
isNil() {
|
|
484
|
+
return this.item.key === void 0 && this.item.value === void 0 && this.left === null && this.right === null && this.color === RB_TREE_COLOR_BLACK;
|
|
485
|
+
}
|
|
486
|
+
_value_less_than(other_node) {
|
|
487
|
+
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;
|
|
488
|
+
}
|
|
489
|
+
less_than(other_node) {
|
|
490
|
+
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);
|
|
491
|
+
}
|
|
492
|
+
_value_equal(other_node) {
|
|
493
|
+
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;
|
|
494
|
+
}
|
|
495
|
+
equal_to(other_node) {
|
|
496
|
+
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);
|
|
497
|
+
}
|
|
498
|
+
intersect(other_node) {
|
|
499
|
+
return this.item.key.intersect(other_node.item.key);
|
|
500
|
+
}
|
|
501
|
+
copy_data(other_node) {
|
|
502
|
+
this.item.key = other_node.item.key, this.item.value = other_node.item.value;
|
|
503
|
+
}
|
|
504
|
+
update_max() {
|
|
505
|
+
if (this.max = this.item.key ? this.item.key.max : void 0, this.right && this.right.max) {
|
|
506
|
+
const comparable_max = this.item.key.constructor.comparable_max;
|
|
507
|
+
this.max = comparable_max(this.max, this.right.max);
|
|
508
|
+
}
|
|
509
|
+
if (this.left && this.left.max) {
|
|
510
|
+
const comparable_max = this.item.key.constructor.comparable_max;
|
|
511
|
+
this.max = comparable_max(this.max, this.left.max);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// Other_node does not intersect any node of left subtree, if this.left.max < other_node.item.key.low
|
|
515
|
+
not_intersect_left_subtree(search_node) {
|
|
516
|
+
const comparable_less_than = this.item.key.constructor.comparable_less_than;
|
|
517
|
+
let high = this.left.max.high !== void 0 ? this.left.max.high : this.left.max;
|
|
518
|
+
return comparable_less_than(high, search_node.item.key.low);
|
|
519
|
+
}
|
|
520
|
+
// Other_node does not intersect right subtree if other_node.item.key.high < this.right.key.low
|
|
521
|
+
not_intersect_right_subtree(search_node) {
|
|
522
|
+
const comparable_less_than = this.item.key.constructor.comparable_less_than;
|
|
523
|
+
let low = this.right.max.low !== void 0 ? this.right.max.low : this.right.item.key.low;
|
|
524
|
+
return comparable_less_than(search_node.item.key.high, low);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
__name(_Node, "Node");
|
|
528
|
+
let Node = _Node;
|
|
529
|
+
const _IntervalTree = class _IntervalTree {
|
|
530
|
+
/**
|
|
531
|
+
* Construct new empty instance of IntervalTree
|
|
532
|
+
*/
|
|
533
|
+
constructor() {
|
|
534
|
+
this.root = null, this.nil_node = new Node();
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Returns number of items stored in the interval tree
|
|
538
|
+
* @returns {number}
|
|
539
|
+
*/
|
|
540
|
+
get size() {
|
|
541
|
+
let count = 0;
|
|
542
|
+
return this.tree_walk(this.root, () => count++), count;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Returns array of sorted keys in the ascending order
|
|
546
|
+
* @returns {Array}
|
|
547
|
+
*/
|
|
548
|
+
get keys() {
|
|
549
|
+
let res = [];
|
|
550
|
+
return this.tree_walk(this.root, (node) => res.push(
|
|
551
|
+
node.item.key.output ? node.item.key.output() : node.item.key
|
|
552
|
+
)), res;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Return array of values in the ascending keys order
|
|
556
|
+
* @returns {Array}
|
|
557
|
+
*/
|
|
558
|
+
get values() {
|
|
559
|
+
let res = [];
|
|
560
|
+
return this.tree_walk(this.root, (node) => res.push(node.item.value)), res;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Returns array of items (<key,value> pairs) in the ascended keys order
|
|
564
|
+
* @returns {Array}
|
|
565
|
+
*/
|
|
566
|
+
get items() {
|
|
567
|
+
let res = [];
|
|
568
|
+
return this.tree_walk(this.root, (node) => res.push({
|
|
569
|
+
key: node.item.key.output ? node.item.key.output() : node.item.key,
|
|
570
|
+
value: node.item.value
|
|
571
|
+
})), res;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Returns true if tree is empty
|
|
575
|
+
* @returns {boolean}
|
|
576
|
+
*/
|
|
577
|
+
isEmpty() {
|
|
578
|
+
return this.root == null || this.root === this.nil_node;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Clear tree
|
|
582
|
+
*/
|
|
583
|
+
clear() {
|
|
584
|
+
this.root = null;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Insert new item into interval tree
|
|
588
|
+
* @param {Interval} key - interval object or array of two numbers [low, high]
|
|
589
|
+
* @param {any} value - value representing any object (optional)
|
|
590
|
+
* @returns {Node} returns reference to inserted node as an object {key:interval, value: value}
|
|
591
|
+
*/
|
|
592
|
+
insert(key, value = key) {
|
|
593
|
+
if (key === void 0) return;
|
|
594
|
+
let insert_node = new Node(key, value, this.nil_node, this.nil_node, null, RB_TREE_COLOR_RED);
|
|
595
|
+
return this.tree_insert(insert_node), this.recalc_max(insert_node), insert_node;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Returns true if item {key,value} exist in the tree
|
|
599
|
+
* @param {Interval} key - interval correspondent to keys stored in the tree
|
|
600
|
+
* @param {any} value - value object to be checked
|
|
601
|
+
* @returns {boolean} true if item {key, value} exist in the tree, false otherwise
|
|
602
|
+
*/
|
|
603
|
+
exist(key, value = key) {
|
|
604
|
+
let search_node = new Node(key, value);
|
|
605
|
+
return !!this.tree_search(this.root, search_node);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Remove entry {key, value} from the tree
|
|
609
|
+
* @param {Interval} key - interval correspondent to keys stored in the tree
|
|
610
|
+
* @param {any} value - value object
|
|
611
|
+
* @returns {boolean} true if item {key, value} deleted, false if not found
|
|
612
|
+
*/
|
|
613
|
+
remove(key, value = key) {
|
|
614
|
+
let search_node = new Node(key, value), delete_node = this.tree_search(this.root, search_node);
|
|
615
|
+
return delete_node && this.tree_delete(delete_node), delete_node;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Returns array of entry values which keys intersect with given interval <br/>
|
|
619
|
+
* If no values stored in the tree, returns array of keys which intersect given interval
|
|
620
|
+
* @param {Interval} interval - search interval, or tuple [low, high]
|
|
621
|
+
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
|
|
622
|
+
* @returns {Array}
|
|
623
|
+
*/
|
|
624
|
+
search(interval, outputMapperFn = (value, key) => value === key ? key.output() : value) {
|
|
625
|
+
let search_node = new Node(interval), resp_nodes = [];
|
|
626
|
+
return this.tree_search_interval(this.root, search_node, resp_nodes), resp_nodes.map((node) => outputMapperFn(node.item.value, node.item.key));
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Returns true if intersection between given and any interval stored in the tree found
|
|
630
|
+
* @param {Interval} interval - search interval or tuple [low, high]
|
|
631
|
+
* @returns {boolean}
|
|
632
|
+
*/
|
|
633
|
+
intersect_any(interval) {
|
|
634
|
+
let search_node = new Node(interval);
|
|
635
|
+
return this.tree_find_any_interval(this.root, search_node);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Tree visitor. For each node implement a callback function. <br/>
|
|
639
|
+
* Method calls a callback function with two parameters (key, value)
|
|
640
|
+
* @param visitor(key,value) - function to be called for each tree item
|
|
641
|
+
*/
|
|
642
|
+
forEach(visitor) {
|
|
643
|
+
this.tree_walk(this.root, (node) => visitor(node.item.key, node.item.value));
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Value Mapper. Walk through every node and map node value to another value
|
|
647
|
+
* @param callback(value,key) - function to be called for each tree item
|
|
648
|
+
*/
|
|
649
|
+
map(callback) {
|
|
650
|
+
const tree = new _IntervalTree();
|
|
651
|
+
return this.tree_walk(this.root, (node) => tree.insert(node.item.key, callback(node.item.value, node.item.key))), tree;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
|
|
655
|
+
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
|
|
656
|
+
* @returns {Iterator}
|
|
657
|
+
*/
|
|
658
|
+
*iterate(interval, outputMapperFn = (value, key) => value === key ? key.output() : value) {
|
|
659
|
+
let node;
|
|
660
|
+
for (interval ? node = this.tree_search_nearest_forward(this.root, new Node(interval)) : this.root && (node = this.local_minimum(this.root)); node; )
|
|
661
|
+
yield outputMapperFn(node.item.value, node.item.key), node = this.tree_successor(node);
|
|
662
|
+
}
|
|
663
|
+
recalc_max(node) {
|
|
664
|
+
let node_current = node;
|
|
665
|
+
for (; node_current.parent != null; )
|
|
666
|
+
node_current.parent.update_max(), node_current = node_current.parent;
|
|
667
|
+
}
|
|
668
|
+
tree_insert(insert_node) {
|
|
669
|
+
let current_node = this.root, parent_node = null;
|
|
670
|
+
if (this.root == null || this.root === this.nil_node)
|
|
671
|
+
this.root = insert_node;
|
|
672
|
+
else {
|
|
673
|
+
for (; current_node !== this.nil_node; )
|
|
674
|
+
parent_node = current_node, insert_node.less_than(current_node) ? current_node = current_node.left : current_node = current_node.right;
|
|
675
|
+
insert_node.parent = parent_node, insert_node.less_than(parent_node) ? parent_node.left = insert_node : parent_node.right = insert_node;
|
|
676
|
+
}
|
|
677
|
+
this.insert_fixup(insert_node);
|
|
678
|
+
}
|
|
679
|
+
// After insertion insert_node may have red-colored parent, and this is a single possible violation
|
|
680
|
+
// Go upwords to the root and re-color until violation will be resolved
|
|
681
|
+
insert_fixup(insert_node) {
|
|
682
|
+
let current_node, uncle_node;
|
|
683
|
+
for (current_node = insert_node; current_node !== this.root && current_node.parent.color === RB_TREE_COLOR_RED; )
|
|
684
|
+
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)));
|
|
685
|
+
this.root.color = RB_TREE_COLOR_BLACK;
|
|
686
|
+
}
|
|
687
|
+
tree_delete(delete_node) {
|
|
688
|
+
let cut_node, fix_node;
|
|
689
|
+
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 && */
|
|
690
|
+
cut_node.color === RB_TREE_COLOR_BLACK && this.delete_fixup(fix_node);
|
|
691
|
+
}
|
|
692
|
+
delete_fixup(fix_node) {
|
|
693
|
+
let current_node = fix_node, brother_node;
|
|
694
|
+
for (; current_node !== this.root && current_node.parent != null && current_node.color === RB_TREE_COLOR_BLACK; )
|
|
695
|
+
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));
|
|
696
|
+
current_node.color = RB_TREE_COLOR_BLACK;
|
|
697
|
+
}
|
|
698
|
+
tree_search(node, search_node) {
|
|
699
|
+
if (!(node == null || node === this.nil_node))
|
|
700
|
+
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);
|
|
701
|
+
}
|
|
702
|
+
tree_search_nearest_forward(node, search_node) {
|
|
703
|
+
let best, curr = node;
|
|
704
|
+
for (; curr && curr !== this.nil_node; )
|
|
705
|
+
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);
|
|
706
|
+
return best || null;
|
|
707
|
+
}
|
|
708
|
+
// Original search_interval method; container res support push() insertion
|
|
709
|
+
// Search all intervals intersecting given one
|
|
710
|
+
tree_search_interval(node, search_node, res) {
|
|
711
|
+
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));
|
|
712
|
+
}
|
|
713
|
+
tree_find_any_interval(node, search_node) {
|
|
714
|
+
let found = !1;
|
|
715
|
+
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;
|
|
716
|
+
}
|
|
717
|
+
local_minimum(node) {
|
|
718
|
+
let node_min = node;
|
|
719
|
+
for (; node_min.left != null && node_min.left !== this.nil_node; )
|
|
720
|
+
node_min = node_min.left;
|
|
721
|
+
return node_min;
|
|
722
|
+
}
|
|
723
|
+
// not in use
|
|
724
|
+
local_maximum(node) {
|
|
725
|
+
let node_max = node;
|
|
726
|
+
for (; node_max.right != null && node_max.right !== this.nil_node; )
|
|
727
|
+
node_max = node_max.right;
|
|
728
|
+
return node_max;
|
|
729
|
+
}
|
|
730
|
+
tree_successor(node) {
|
|
731
|
+
let node_successor, current_node, parent_node;
|
|
732
|
+
if (node.right !== this.nil_node)
|
|
733
|
+
node_successor = this.local_minimum(node.right);
|
|
734
|
+
else {
|
|
735
|
+
for (current_node = node, parent_node = node.parent; parent_node != null && parent_node.right === current_node; )
|
|
736
|
+
current_node = parent_node, parent_node = parent_node.parent;
|
|
737
|
+
node_successor = parent_node;
|
|
738
|
+
}
|
|
739
|
+
return node_successor;
|
|
740
|
+
}
|
|
741
|
+
// | right-rotate(T,y) |
|
|
742
|
+
// y ---------------. x
|
|
743
|
+
// / \ / \
|
|
744
|
+
// x c left-rotate(T,x) a y
|
|
745
|
+
// / \ <--------------- / \
|
|
746
|
+
// a b b c
|
|
747
|
+
rotate_left(x) {
|
|
748
|
+
let y = x.right;
|
|
749
|
+
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();
|
|
750
|
+
}
|
|
751
|
+
rotate_right(y) {
|
|
752
|
+
let x = y.left;
|
|
753
|
+
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();
|
|
754
|
+
}
|
|
755
|
+
tree_walk(node, action) {
|
|
756
|
+
node != null && node !== this.nil_node && (this.tree_walk(node.left, action), action(node), this.tree_walk(node.right, action));
|
|
757
|
+
}
|
|
758
|
+
/* Return true if all red nodes have exactly two black child nodes */
|
|
759
|
+
testRedBlackProperty() {
|
|
760
|
+
let res = !0;
|
|
761
|
+
return this.tree_walk(this.root, function(node) {
|
|
762
|
+
node.color === RB_TREE_COLOR_RED && (node.left.color === RB_TREE_COLOR_BLACK && node.right.color === RB_TREE_COLOR_BLACK || (res = !1));
|
|
763
|
+
}), res;
|
|
764
|
+
}
|
|
765
|
+
/* Throw error if not every path from root to bottom has same black height */
|
|
766
|
+
testBlackHeightProperty(node) {
|
|
767
|
+
let height = 0, heightLeft = 0, heightRight = 0;
|
|
768
|
+
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)
|
|
769
|
+
throw new Error("Red-black height property violated");
|
|
770
|
+
return height += heightLeft, height;
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
__name(_IntervalTree, "IntervalTree");
|
|
774
|
+
let IntervalTree = _IntervalTree;
|
|
775
|
+
const _RuleMatrix = class _RuleMatrix {
|
|
776
|
+
constructor(value, _unitId, _subUnitId, _univerInstanceService, _disableTree = !1) {
|
|
777
|
+
__publicField(this, "_map");
|
|
778
|
+
__publicField(this, "_tree", /* @__PURE__ */ new Map());
|
|
779
|
+
__publicField(this, "_dirty", !0);
|
|
780
|
+
__publicField(this, "_buildTree", /* @__PURE__ */ __name(() => {
|
|
781
|
+
if (!this._dirty || this._disableTree)
|
|
782
|
+
return;
|
|
783
|
+
const map = /* @__PURE__ */ new Map();
|
|
784
|
+
this._map.forEach((ranges, ruleId) => {
|
|
785
|
+
ranges.forEach((range) => {
|
|
786
|
+
for (let col = range.startColumn; col <= range.endColumn; col++) {
|
|
787
|
+
let items = map.get(col);
|
|
788
|
+
items || (items = [], map.set(col, items)), items.push({
|
|
789
|
+
startRow: range.startRow,
|
|
790
|
+
endRow: range.endRow,
|
|
791
|
+
ruleId
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
});
|
|
796
|
+
const treeMap = /* @__PURE__ */ new Map();
|
|
797
|
+
map.forEach((items, col) => {
|
|
798
|
+
const tree = new IntervalTree();
|
|
799
|
+
items.forEach((item) => {
|
|
800
|
+
tree.insert([item.startRow, item.endRow], item.ruleId);
|
|
801
|
+
}), treeMap.set(col, tree);
|
|
802
|
+
}), this._tree = treeMap, this._dirty = !1;
|
|
803
|
+
}, "_buildTree"));
|
|
804
|
+
__publicField(this, "_debonceBuildTree", debounce(this._buildTree, 0));
|
|
805
|
+
this._unitId = _unitId, this._subUnitId = _subUnitId, this._univerInstanceService = _univerInstanceService, this._disableTree = _disableTree, this._map = value, this._buildTree();
|
|
806
|
+
}
|
|
807
|
+
get _worksheet() {
|
|
808
|
+
var _a7;
|
|
809
|
+
return (_a7 = this._univerInstanceService.getUnit(this._unitId, UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a7.getSheetBySheetId(this._subUnitId);
|
|
810
|
+
}
|
|
811
|
+
addRule(rule) {
|
|
812
|
+
if (!this._worksheet)
|
|
813
|
+
return;
|
|
814
|
+
const ruleId = rule.uid, ranges = rule.ranges.map((range) => Range.transformRange(range, this._worksheet));
|
|
815
|
+
this._map.forEach((value, key) => {
|
|
816
|
+
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
817
|
+
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
818
|
+
}), this._dirty = !0, this._map.set(ruleId, ranges), this._debonceBuildTree();
|
|
819
|
+
}
|
|
820
|
+
removeRange(_ranges) {
|
|
821
|
+
if (!this._worksheet)
|
|
822
|
+
return;
|
|
823
|
+
const ranges = _ranges.map((range) => Range.transformRange(range, this._worksheet));
|
|
824
|
+
this._map.forEach((value, key) => {
|
|
825
|
+
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
826
|
+
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
827
|
+
}), this._dirty = !0, this._debonceBuildTree();
|
|
828
|
+
}
|
|
829
|
+
removeRule(rule) {
|
|
830
|
+
this._map.delete(rule.uid), this._dirty = !0, this._debonceBuildTree();
|
|
831
|
+
}
|
|
832
|
+
updateRange(ruleId, _newRanges) {
|
|
833
|
+
if (!this._worksheet)
|
|
834
|
+
return;
|
|
835
|
+
this._map.delete(ruleId);
|
|
836
|
+
const ranges = _newRanges.map((range) => Range.transformRange(range, this._worksheet));
|
|
837
|
+
this._map.forEach((value, key) => {
|
|
838
|
+
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
839
|
+
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
840
|
+
}), this._map.set(ruleId, ranges), this._dirty = !0, this._debonceBuildTree();
|
|
841
|
+
}
|
|
842
|
+
addRangeRules(rules) {
|
|
843
|
+
rules.forEach(({ id: ruleId, ranges }) => {
|
|
844
|
+
if (!ranges.length)
|
|
845
|
+
return;
|
|
846
|
+
let current = this._map.get(ruleId);
|
|
847
|
+
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) => {
|
|
848
|
+
if (key === ruleId)
|
|
849
|
+
return;
|
|
850
|
+
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
851
|
+
newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
|
|
852
|
+
});
|
|
853
|
+
}), this._dirty = !0, this._debonceBuildTree();
|
|
854
|
+
}
|
|
855
|
+
diff(rules) {
|
|
856
|
+
const mutations = [];
|
|
857
|
+
let deleteIndex = 0;
|
|
858
|
+
return rules.forEach((rule, index) => {
|
|
859
|
+
var _a7;
|
|
860
|
+
const newRanges = (_a7 = this._map.get(rule.uid)) != null ? _a7 : [], oldRanges = rule.ranges;
|
|
861
|
+
newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) && mutations.push({
|
|
862
|
+
type: "update",
|
|
863
|
+
ruleId: rule.uid,
|
|
864
|
+
oldRanges,
|
|
865
|
+
newRanges: Rectangle.sort(newRanges),
|
|
866
|
+
rule
|
|
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 _a7;
|
|
879
|
+
const newRanges = (_a7 = this._map.get(rule.uid)) != null ? _a7 : [], 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: Rectangle.sort(newRanges),
|
|
885
|
+
rule
|
|
886
|
+
}), newRanges.length === 0 && (mutations.push({
|
|
887
|
+
type: "delete",
|
|
888
|
+
rule,
|
|
889
|
+
index: index - deleteIndex
|
|
890
|
+
}), deleteIndex++);
|
|
891
|
+
}), Array.from(additionRules).forEach((rule) => {
|
|
892
|
+
var _a7;
|
|
893
|
+
const newRanges = (_a7 = this._map.get(rule.uid)) != null ? _a7 : [];
|
|
894
|
+
mutations.push({
|
|
895
|
+
type: "add",
|
|
896
|
+
rule: {
|
|
897
|
+
...rule,
|
|
898
|
+
ranges: Rectangle.sort(newRanges)
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
}), mutations;
|
|
902
|
+
}
|
|
903
|
+
clone() {
|
|
904
|
+
return new _RuleMatrix(
|
|
905
|
+
new Map(Tools.deepClone(Array.from(this._map.entries()))),
|
|
906
|
+
this._unitId,
|
|
907
|
+
this._subUnitId,
|
|
908
|
+
this._univerInstanceService,
|
|
909
|
+
// disable tree on cloned matrix, cause there is no need to search
|
|
910
|
+
!0
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
getValue(row, col) {
|
|
914
|
+
this._dirty && this._buildTree();
|
|
915
|
+
const tree = this._tree.get(col);
|
|
916
|
+
if (!tree)
|
|
917
|
+
return;
|
|
918
|
+
const result = tree.search([row, row]);
|
|
919
|
+
return result.length > 0 ? result[0] : void 0;
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
__name(_RuleMatrix, "RuleMatrix");
|
|
923
|
+
let RuleMatrix = _RuleMatrix;
|
|
924
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
925
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
926
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
927
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
928
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a5;
|
|
929
|
+
let SheetDataValidationModel = (_a5 = class extends Disposable {
|
|
930
|
+
constructor(_dataValidationModel, _univerInstanceService, _dataValidatorRegistryService, _dataValidationCacheService, _dataValidationFormulaService, _dataValidationCustomFormulaService, _commandService) {
|
|
931
|
+
super();
|
|
932
|
+
__publicField(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
|
|
933
|
+
__publicField(this, "_validStatusChange$", new Subject());
|
|
934
|
+
__publicField(this, "_ruleChange$", new Subject());
|
|
935
|
+
__publicField(this, "ruleChange$", this._ruleChange$.asObservable());
|
|
936
|
+
__publicField(this, "validStatusChange$", this._validStatusChange$.asObservable());
|
|
937
|
+
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(() => {
|
|
938
|
+
this._ruleChange$.complete(), this._validStatusChange$.complete();
|
|
939
|
+
}), this._initUniverInstanceListener();
|
|
940
|
+
}
|
|
941
|
+
_initUniverInstanceListener() {
|
|
942
|
+
this.disposeWithMe(
|
|
943
|
+
this._univerInstanceService.unitDisposed$.subscribe((unit) => {
|
|
944
|
+
this._ruleMatrixMap.delete(unit.getUnitId());
|
|
945
|
+
})
|
|
946
|
+
), this.disposeWithMe(
|
|
947
|
+
this._commandService.onCommandExecuted((command) => {
|
|
948
|
+
if (command.id === RemoveSheetMutation.id) {
|
|
949
|
+
const { unitId, subUnitId } = command.params, subUnitMap = this._ruleMatrixMap.get(unitId);
|
|
950
|
+
subUnitMap && subUnitMap.delete(subUnitId);
|
|
951
|
+
}
|
|
952
|
+
})
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
_initRuleUpdateListener() {
|
|
956
|
+
const allRules = this._dataValidationModel.getAll();
|
|
957
|
+
for (const [unitId, subUnitMap] of allRules)
|
|
958
|
+
for (const [subUnitId, rules] of subUnitMap)
|
|
959
|
+
for (const rule of rules)
|
|
960
|
+
this._addRule(unitId, subUnitId, rule), this._ruleChange$.next({
|
|
961
|
+
type: "add",
|
|
962
|
+
unitId,
|
|
963
|
+
subUnitId,
|
|
964
|
+
rule,
|
|
965
|
+
source: "patched"
|
|
966
|
+
});
|
|
967
|
+
this.disposeWithMe(
|
|
968
|
+
this._dataValidationModel.ruleChange$.subscribe((ruleChange) => {
|
|
969
|
+
switch (ruleChange.type) {
|
|
970
|
+
case "add":
|
|
971
|
+
this._addRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
972
|
+
break;
|
|
973
|
+
case "update":
|
|
974
|
+
this._updateRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule.uid, ruleChange.oldRule, ruleChange.updatePayload);
|
|
975
|
+
break;
|
|
976
|
+
case "remove":
|
|
977
|
+
this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
this._ruleChange$.next(ruleChange);
|
|
981
|
+
})
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
_ensureRuleMatrix(unitId, subUnitId) {
|
|
985
|
+
let unitMap = this._ruleMatrixMap.get(unitId);
|
|
986
|
+
unitMap || (unitMap = /* @__PURE__ */ new Map(), this._ruleMatrixMap.set(unitId, unitMap));
|
|
987
|
+
let matrix = unitMap.get(subUnitId);
|
|
988
|
+
return matrix || (matrix = new RuleMatrix(/* @__PURE__ */ new Map(), unitId, subUnitId, this._univerInstanceService), unitMap.set(subUnitId, matrix)), matrix;
|
|
989
|
+
}
|
|
990
|
+
_addRuleSideEffect(unitId, subUnitId, rule) {
|
|
991
|
+
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);
|
|
992
|
+
}
|
|
993
|
+
_addRule(unitId, subUnitId, rule) {
|
|
994
|
+
(Array.isArray(rule) ? rule : [rule]).forEach((item) => {
|
|
995
|
+
this._addRuleSideEffect(unitId, subUnitId, item);
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
_updateRule(unitId, subUnitId, ruleId, oldRule, payload) {
|
|
999
|
+
const ruleMatrix = this._ensureRuleMatrix(unitId, subUnitId);
|
|
1000
|
+
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, {
|
|
1001
|
+
...oldRule,
|
|
1002
|
+
...payload.payload
|
|
1003
|
+
}));
|
|
1004
|
+
}
|
|
1005
|
+
_removeRule(unitId, subUnitId, oldRule) {
|
|
1006
|
+
this._ensureRuleMatrix(unitId, subUnitId).removeRule(oldRule), this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule), oldRule.type === DataValidationType.CUSTOM && this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, oldRule.uid);
|
|
1007
|
+
}
|
|
1008
|
+
getValidator(type) {
|
|
1009
|
+
return this._dataValidatorRegistryService.getValidatorItem(type);
|
|
1010
|
+
}
|
|
1011
|
+
getRuleIdByLocation(unitId, subUnitId, row, col) {
|
|
1012
|
+
return this._ensureRuleMatrix(unitId, subUnitId).getValue(row, col);
|
|
1013
|
+
}
|
|
1014
|
+
getRuleByLocation(unitId, subUnitId, row, col) {
|
|
1015
|
+
const ruleId = this.getRuleIdByLocation(unitId, subUnitId, row, col);
|
|
1016
|
+
if (ruleId)
|
|
1017
|
+
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1018
|
+
}
|
|
1019
|
+
validator(rule, pos, _onCompete) {
|
|
1020
|
+
const { col, row, unitId, subUnitId, worksheet } = pos, ruleId = rule.uid, formula1 = rule.formula1, formula2 = rule.formula2, onCompete = /* @__PURE__ */ __name((status, changed) => {
|
|
1021
|
+
_onCompete && _onCompete(status, changed), changed && this._validStatusChange$.next({
|
|
1022
|
+
unitId,
|
|
1023
|
+
subUnitId,
|
|
1024
|
+
ruleId: rule.uid,
|
|
1025
|
+
status,
|
|
1026
|
+
row,
|
|
1027
|
+
col
|
|
1028
|
+
});
|
|
1029
|
+
}, "onCompete"), cell = worksheet.getCellValueOnly(row, col), validator = this.getValidator(rule.type), cellRaw = worksheet.getCellRaw(row, col), cellValue = getCellValueOrigin(cellRaw), interceptValue = getCellValueOrigin(cell);
|
|
1030
|
+
if (validator) {
|
|
1031
|
+
const cache = this._dataValidationCacheService.ensureCache(unitId, subUnitId), current = cache.getValue(row, col);
|
|
1032
|
+
return !current || current.value !== cellValue || current.interceptValue !== interceptValue || current.ruleId !== ruleId || current.formula1 !== formula1 || current.formula2 !== formula2 ? (cache.setValue(row, col, {
|
|
1033
|
+
value: cellValue,
|
|
1034
|
+
interceptValue,
|
|
1035
|
+
status: DataValidationStatus.VALIDATING,
|
|
1036
|
+
ruleId,
|
|
1037
|
+
formula1: formula1 || "",
|
|
1038
|
+
formula2: formula2 || ""
|
|
1039
|
+
}), validator.validator(
|
|
1040
|
+
{
|
|
1041
|
+
value: cellValue,
|
|
1042
|
+
unitId,
|
|
1043
|
+
subUnitId,
|
|
1044
|
+
row,
|
|
1045
|
+
column: col,
|
|
1046
|
+
worksheet: pos.worksheet,
|
|
1047
|
+
workbook: pos.workbook,
|
|
1048
|
+
interceptValue: getCellValueOrigin(cell),
|
|
1049
|
+
t: cellRaw == null ? void 0 : cellRaw.t
|
|
1050
|
+
},
|
|
1051
|
+
rule
|
|
1052
|
+
).then((status) => {
|
|
1053
|
+
const realStatus = status ? DataValidationStatus.VALID : DataValidationStatus.INVALID;
|
|
1054
|
+
cache.setValue(row, col, {
|
|
1055
|
+
value: cellValue,
|
|
1056
|
+
status: realStatus,
|
|
1057
|
+
ruleId,
|
|
1058
|
+
interceptValue,
|
|
1059
|
+
formula1: formula1 || "",
|
|
1060
|
+
formula2: formula2 || ""
|
|
1061
|
+
}), onCompete(realStatus, !0);
|
|
1062
|
+
}), DataValidationStatus.VALIDATING) : (onCompete(current.status, !1), current.status);
|
|
1063
|
+
} else
|
|
1064
|
+
return onCompete(DataValidationStatus.VALID, !1), DataValidationStatus.VALID;
|
|
1065
|
+
}
|
|
1066
|
+
getRuleErrorMsg(unitId, subUnitId, ruleId) {
|
|
1067
|
+
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1068
|
+
if (!rule)
|
|
1069
|
+
return "";
|
|
1070
|
+
const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
|
|
1071
|
+
return rule.error ? rule.error : validator ? validator.getRuleFinalError(rule) : "";
|
|
1072
|
+
}
|
|
1073
|
+
getRuleObjectMatrix(unitId, subUnitId) {
|
|
1074
|
+
return this._ensureRuleMatrix(unitId, subUnitId);
|
|
1075
|
+
}
|
|
1076
|
+
getRuleById(unitId, subUnitId, ruleId) {
|
|
1077
|
+
return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1078
|
+
}
|
|
1079
|
+
getRuleIndex(unitId, subUnitId, ruleId) {
|
|
1080
|
+
return this._dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId);
|
|
1081
|
+
}
|
|
1082
|
+
getRules(unitId, subUnitId) {
|
|
1083
|
+
return [...this._dataValidationModel.getRules(unitId, subUnitId)];
|
|
1084
|
+
}
|
|
1085
|
+
getUnitRules(unitId) {
|
|
1086
|
+
return this._dataValidationModel.getUnitRules(unitId);
|
|
1087
|
+
}
|
|
1088
|
+
deleteUnitRules(unitId) {
|
|
1089
|
+
return this._dataValidationModel.deleteUnitRules(unitId);
|
|
1090
|
+
}
|
|
1091
|
+
getSubUnitIds(unitId) {
|
|
1092
|
+
return this._dataValidationModel.getSubUnitIds(unitId);
|
|
1093
|
+
}
|
|
1094
|
+
getAll() {
|
|
1095
|
+
return this._dataValidationModel.getAll();
|
|
1096
|
+
}
|
|
1097
|
+
}, __name(_a5, "SheetDataValidationModel"), _a5);
|
|
1098
|
+
SheetDataValidationModel = __decorateClass$1([
|
|
1099
|
+
__decorateParam$1(0, Inject(DataValidationModel)),
|
|
1100
|
+
__decorateParam$1(1, IUniverInstanceService),
|
|
1101
|
+
__decorateParam$1(2, Inject(DataValidatorRegistryService)),
|
|
1102
|
+
__decorateParam$1(3, Inject(DataValidationCacheService)),
|
|
1103
|
+
__decorateParam$1(4, Inject(DataValidationFormulaService)),
|
|
1104
|
+
__decorateParam$1(5, Inject(DataValidationCustomFormulaService)),
|
|
1105
|
+
__decorateParam$1(6, ICommandService)
|
|
1106
|
+
], SheetDataValidationModel);
|
|
1107
|
+
function getFormulaResult(result) {
|
|
1108
|
+
var _a7, _b;
|
|
1109
|
+
return (_b = (_a7 = result == null ? void 0 : result[0]) == null ? void 0 : _a7[0]) == null ? void 0 : _b.v;
|
|
1110
|
+
}
|
|
1111
|
+
__name(getFormulaResult, "getFormulaResult");
|
|
1112
|
+
function getFormulaCellData(result) {
|
|
1113
|
+
var _a7;
|
|
1114
|
+
return (_a7 = result == null ? void 0 : result[0]) == null ? void 0 : _a7[0];
|
|
1115
|
+
}
|
|
1116
|
+
__name(getFormulaCellData, "getFormulaCellData");
|
|
1117
|
+
function isLegalFormulaResult(res) {
|
|
1118
|
+
return !ERROR_TYPE_SET.has(res);
|
|
1119
|
+
}
|
|
1120
|
+
__name(isLegalFormulaResult, "isLegalFormulaResult");
|
|
1121
|
+
const CHECKBOX_FORMULA_1 = 1, CHECKBOX_FORMULA_2 = 0;
|
|
1122
|
+
function getFailMessage(formula, localeService) {
|
|
1123
|
+
return Tools.isBlank(formula) ? localeService.t("dataValidation.validFail.value") : isFormulaString(formula) ? localeService.t("dataValidation.validFail.primitive") : "";
|
|
1124
|
+
}
|
|
1125
|
+
__name(getFailMessage, "getFailMessage");
|
|
1126
|
+
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 {
|
|
1127
|
+
constructor() {
|
|
1128
|
+
super(...arguments);
|
|
1129
|
+
__publicField(this, "id", DataValidationType.CHECKBOX);
|
|
1130
|
+
__publicField(this, "title", "dataValidation.checkbox.title");
|
|
1131
|
+
__publicField(this, "operators", []);
|
|
1132
|
+
__publicField(this, "scopes", ["sheet"]);
|
|
1133
|
+
__publicField(this, "_formulaService", this.injector.get(DataValidationFormulaService));
|
|
1134
|
+
__publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name((rule, cellValue, pos) => {
|
|
1135
|
+
const { formula1, formula2 } = this.parseFormulaSync(rule, pos.unitId, pos.subUnitId), valueStr = `${cellValue != null ? cellValue : ""}`;
|
|
1136
|
+
return !valueStr || valueStr === `${formula1}` || valueStr === `${formula2}`;
|
|
1137
|
+
}, "skipDefaultFontRender"));
|
|
1138
|
+
}
|
|
1139
|
+
validatorFormula(rule, unitId, subUnitId) {
|
|
1140
|
+
const { formula1, formula2 } = rule, isEqual = formula1 === formula2;
|
|
1141
|
+
if (Tools.isBlank(formula1) && Tools.isBlank(formula2))
|
|
1142
|
+
return {
|
|
1143
|
+
success: !0
|
|
1144
|
+
};
|
|
1145
|
+
if (isEqual)
|
|
1146
|
+
return {
|
|
1147
|
+
success: !1,
|
|
1148
|
+
formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
|
|
1149
|
+
formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
|
|
1150
|
+
};
|
|
1151
|
+
const error1 = getFailMessage(formula1, this.localeService), error2 = getFailMessage(formula2, this.localeService);
|
|
1152
|
+
return {
|
|
1153
|
+
success: !error1 && !error2,
|
|
1154
|
+
formula1: error1,
|
|
1155
|
+
formula2: error2
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
async parseFormula(rule, unitId, subUnitId) {
|
|
1159
|
+
var _a7, _b;
|
|
1160
|
+
const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_a7 = results == null ? void 0 : results[0]) == null ? void 0 : _a7.result) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2, isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
|
|
1161
|
+
return {
|
|
1162
|
+
formula1: transformCheckboxValue(originFormula1),
|
|
1163
|
+
formula2: transformCheckboxValue(originFormula2),
|
|
1164
|
+
originFormula1,
|
|
1165
|
+
originFormula2,
|
|
1166
|
+
isFormulaValid
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
getExtraStyle(rule, value) {
|
|
1170
|
+
return {
|
|
1171
|
+
tb: WrapStrategy.CLIP
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
parseFormulaSync(rule, unitId, subUnitId) {
|
|
1175
|
+
var _a7, _b;
|
|
1176
|
+
const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_a7 = results == null ? void 0 : results[0]) == null ? void 0 : _a7.result) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2;
|
|
1177
|
+
return {
|
|
1178
|
+
formula1: transformCheckboxValue(originFormula1),
|
|
1179
|
+
formula2: transformCheckboxValue(originFormula2),
|
|
1180
|
+
originFormula1,
|
|
1181
|
+
originFormula2
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
async isValidType(cellInfo, formula, rule) {
|
|
1185
|
+
const { value, unitId, subUnitId } = cellInfo, { formula1, formula2, originFormula1, originFormula2 } = await this.parseFormula(rule, unitId, subUnitId);
|
|
1186
|
+
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 : ""));
|
|
1187
|
+
}
|
|
1188
|
+
generateRuleErrorMessage(rule) {
|
|
1189
|
+
return this.localeService.t("dataValidation.checkbox.error");
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
__name(_CheckboxValidator, "CheckboxValidator");
|
|
1193
|
+
let CheckboxValidator = _CheckboxValidator;
|
|
1194
|
+
var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
1195
|
+
function getDefaultExportFromCjs(x) {
|
|
1196
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
|
|
1197
|
+
}
|
|
1198
|
+
__name(getDefaultExportFromCjs, "getDefaultExportFromCjs");
|
|
1199
|
+
var dayjs_min = { exports: {} };
|
|
1200
|
+
(function(module, exports) {
|
|
1201
|
+
(function(t, e) {
|
|
1202
|
+
module.exports = e();
|
|
1203
|
+
})(commonjsGlobal, function() {
|
|
1204
|
+
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) {
|
|
1205
|
+
var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
|
|
1206
|
+
return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
|
|
1207
|
+
}, "ordinal") }, m = /* @__PURE__ */ __name(function(t2, e2, n2) {
|
|
1208
|
+
var r2 = String(t2);
|
|
1209
|
+
return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
|
|
1210
|
+
}, "m"), v = { s: m, z: /* @__PURE__ */ __name(function(t2) {
|
|
1211
|
+
var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
|
|
1212
|
+
return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
|
|
1213
|
+
}, "z"), m: /* @__PURE__ */ __name(function t2(e2, n2) {
|
|
1214
|
+
if (e2.date() < n2.date()) return -t2(n2, e2);
|
|
1215
|
+
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);
|
|
1216
|
+
return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
|
|
1217
|
+
}, "t"), a: /* @__PURE__ */ __name(function(t2) {
|
|
1218
|
+
return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
|
|
1219
|
+
}, "a"), p: /* @__PURE__ */ __name(function(t2) {
|
|
1220
|
+
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$/, "");
|
|
1221
|
+
}, "p"), u: /* @__PURE__ */ __name(function(t2) {
|
|
1222
|
+
return t2 === void 0;
|
|
1223
|
+
}, "u") }, g = "en", D = {};
|
|
1224
|
+
D[g] = M;
|
|
1225
|
+
var p = "$isDayjsObject", S = /* @__PURE__ */ __name(function(t2) {
|
|
1226
|
+
return t2 instanceof _ || !(!t2 || !t2[p]);
|
|
1227
|
+
}, "S"), w = /* @__PURE__ */ __name(function t2(e2, n2, r2) {
|
|
1228
|
+
var i2;
|
|
1229
|
+
if (!e2) return g;
|
|
1230
|
+
if (typeof e2 == "string") {
|
|
1231
|
+
var s2 = e2.toLowerCase();
|
|
1232
|
+
D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
|
|
1233
|
+
var u2 = e2.split("-");
|
|
1234
|
+
if (!i2 && u2.length > 1) return t2(u2[0]);
|
|
1235
|
+
} else {
|
|
1236
|
+
var a2 = e2.name;
|
|
1237
|
+
D[a2] = e2, i2 = a2;
|
|
1238
|
+
}
|
|
1239
|
+
return !r2 && i2 && (g = i2), i2 || !r2 && g;
|
|
1240
|
+
}, "t"), O = /* @__PURE__ */ __name(function(t2, e2) {
|
|
1241
|
+
if (S(t2)) return t2.clone();
|
|
1242
|
+
var n2 = typeof e2 == "object" ? e2 : {};
|
|
1243
|
+
return n2.date = t2, n2.args = arguments, new _(n2);
|
|
1244
|
+
}, "O"), b = v;
|
|
1245
|
+
b.l = w, b.i = S, b.w = function(t2, e2) {
|
|
1246
|
+
return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
|
|
1247
|
+
};
|
|
1248
|
+
var _ = function() {
|
|
1249
|
+
function M2(t2) {
|
|
1250
|
+
this.$L = w(t2.locale, null, !0), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = !0;
|
|
1251
|
+
}
|
|
1252
|
+
__name(M2, "M");
|
|
1253
|
+
var m2 = M2.prototype;
|
|
1254
|
+
return m2.parse = function(t2) {
|
|
1255
|
+
this.$d = function(t3) {
|
|
1256
|
+
var e2 = t3.date, n2 = t3.utc;
|
|
1257
|
+
if (e2 === null) return /* @__PURE__ */ new Date(NaN);
|
|
1258
|
+
if (b.u(e2)) return /* @__PURE__ */ new Date();
|
|
1259
|
+
if (e2 instanceof Date) return new Date(e2);
|
|
1260
|
+
if (typeof e2 == "string" && !/Z$/i.test(e2)) {
|
|
1261
|
+
var r2 = e2.match($);
|
|
1262
|
+
if (r2) {
|
|
1263
|
+
var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
|
|
1264
|
+
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);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return new Date(e2);
|
|
1268
|
+
}(t2), this.init();
|
|
1269
|
+
}, m2.init = function() {
|
|
1270
|
+
var t2 = this.$d;
|
|
1271
|
+
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();
|
|
1272
|
+
}, m2.$utils = function() {
|
|
1273
|
+
return b;
|
|
1274
|
+
}, m2.isValid = function() {
|
|
1275
|
+
return this.$d.toString() !== l;
|
|
1276
|
+
}, m2.isSame = function(t2, e2) {
|
|
1277
|
+
var n2 = O(t2);
|
|
1278
|
+
return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
|
|
1279
|
+
}, m2.isAfter = function(t2, e2) {
|
|
1280
|
+
return O(t2) < this.startOf(e2);
|
|
1281
|
+
}, m2.isBefore = function(t2, e2) {
|
|
1282
|
+
return this.endOf(e2) < O(t2);
|
|
1283
|
+
}, m2.$g = function(t2, e2, n2) {
|
|
1284
|
+
return b.u(t2) ? this[e2] : this.set(n2, t2);
|
|
1285
|
+
}, m2.unix = function() {
|
|
1286
|
+
return Math.floor(this.valueOf() / 1e3);
|
|
1287
|
+
}, m2.valueOf = function() {
|
|
1288
|
+
return this.$d.getTime();
|
|
1289
|
+
}, m2.startOf = function(t2, e2) {
|
|
1290
|
+
var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = /* @__PURE__ */ __name(function(t3, e3) {
|
|
1291
|
+
var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
|
|
1292
|
+
return r2 ? i2 : i2.endOf(a);
|
|
1293
|
+
}, "l"), $2 = /* @__PURE__ */ __name(function(t3, e3) {
|
|
1294
|
+
return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
|
|
1295
|
+
}, "$"), y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
|
|
1296
|
+
switch (f2) {
|
|
1297
|
+
case h:
|
|
1298
|
+
return r2 ? l2(1, 0) : l2(31, 11);
|
|
1299
|
+
case c:
|
|
1300
|
+
return r2 ? l2(1, M3) : l2(0, M3 + 1);
|
|
1301
|
+
case o:
|
|
1302
|
+
var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
|
|
1303
|
+
return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
|
|
1304
|
+
case a:
|
|
1305
|
+
case d:
|
|
1306
|
+
return $2(v2 + "Hours", 0);
|
|
1307
|
+
case u:
|
|
1308
|
+
return $2(v2 + "Minutes", 1);
|
|
1309
|
+
case s:
|
|
1310
|
+
return $2(v2 + "Seconds", 2);
|
|
1311
|
+
case i:
|
|
1312
|
+
return $2(v2 + "Milliseconds", 3);
|
|
1313
|
+
default:
|
|
1314
|
+
return this.clone();
|
|
1315
|
+
}
|
|
1316
|
+
}, m2.endOf = function(t2) {
|
|
1317
|
+
return this.startOf(t2, !1);
|
|
1318
|
+
}, m2.$set = function(t2, e2) {
|
|
1319
|
+
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;
|
|
1320
|
+
if (o2 === c || o2 === h) {
|
|
1321
|
+
var y2 = this.clone().set(d, 1);
|
|
1322
|
+
y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
|
|
1323
|
+
} else l2 && this.$d[l2]($2);
|
|
1324
|
+
return this.init(), this;
|
|
1325
|
+
}, m2.set = function(t2, e2) {
|
|
1326
|
+
return this.clone().$set(t2, e2);
|
|
1327
|
+
}, m2.get = function(t2) {
|
|
1328
|
+
return this[b.p(t2)]();
|
|
1329
|
+
}, m2.add = function(r2, f2) {
|
|
1330
|
+
var d2, l2 = this;
|
|
1331
|
+
r2 = Number(r2);
|
|
1332
|
+
var $2 = b.p(f2), y2 = /* @__PURE__ */ __name(function(t2) {
|
|
1333
|
+
var e2 = O(l2);
|
|
1334
|
+
return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
|
|
1335
|
+
}, "y");
|
|
1336
|
+
if ($2 === c) return this.set(c, this.$M + r2);
|
|
1337
|
+
if ($2 === h) return this.set(h, this.$y + r2);
|
|
1338
|
+
if ($2 === a) return y2(1);
|
|
1339
|
+
if ($2 === o) return y2(7);
|
|
1340
|
+
var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
|
|
1341
|
+
return b.w(m3, this);
|
|
1342
|
+
}, m2.subtract = function(t2, e2) {
|
|
1343
|
+
return this.add(-1 * t2, e2);
|
|
1344
|
+
}, m2.format = function(t2) {
|
|
1345
|
+
var e2 = this, n2 = this.$locale();
|
|
1346
|
+
if (!this.isValid()) return n2.invalidDate || l;
|
|
1347
|
+
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) {
|
|
1348
|
+
return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
|
|
1349
|
+
}, "h"), d2 = /* @__PURE__ */ __name(function(t3) {
|
|
1350
|
+
return b.s(s2 % 12 || 12, t3, "0");
|
|
1351
|
+
}, "d"), $2 = f2 || function(t3, e3, n3) {
|
|
1352
|
+
var r3 = t3 < 12 ? "AM" : "PM";
|
|
1353
|
+
return n3 ? r3.toLowerCase() : r3;
|
|
1354
|
+
};
|
|
1355
|
+
return r2.replace(y, function(t3, r3) {
|
|
1356
|
+
return r3 || function(t4) {
|
|
1357
|
+
switch (t4) {
|
|
1358
|
+
case "YY":
|
|
1359
|
+
return String(e2.$y).slice(-2);
|
|
1360
|
+
case "YYYY":
|
|
1361
|
+
return b.s(e2.$y, 4, "0");
|
|
1362
|
+
case "M":
|
|
1363
|
+
return a2 + 1;
|
|
1364
|
+
case "MM":
|
|
1365
|
+
return b.s(a2 + 1, 2, "0");
|
|
1366
|
+
case "MMM":
|
|
1367
|
+
return h2(n2.monthsShort, a2, c2, 3);
|
|
1368
|
+
case "MMMM":
|
|
1369
|
+
return h2(c2, a2);
|
|
1370
|
+
case "D":
|
|
1371
|
+
return e2.$D;
|
|
1372
|
+
case "DD":
|
|
1373
|
+
return b.s(e2.$D, 2, "0");
|
|
1374
|
+
case "d":
|
|
1375
|
+
return String(e2.$W);
|
|
1376
|
+
case "dd":
|
|
1377
|
+
return h2(n2.weekdaysMin, e2.$W, o2, 2);
|
|
1378
|
+
case "ddd":
|
|
1379
|
+
return h2(n2.weekdaysShort, e2.$W, o2, 3);
|
|
1380
|
+
case "dddd":
|
|
1381
|
+
return o2[e2.$W];
|
|
1382
|
+
case "H":
|
|
1383
|
+
return String(s2);
|
|
1384
|
+
case "HH":
|
|
1385
|
+
return b.s(s2, 2, "0");
|
|
1386
|
+
case "h":
|
|
1387
|
+
return d2(1);
|
|
1388
|
+
case "hh":
|
|
1389
|
+
return d2(2);
|
|
1390
|
+
case "a":
|
|
1391
|
+
return $2(s2, u2, !0);
|
|
1392
|
+
case "A":
|
|
1393
|
+
return $2(s2, u2, !1);
|
|
1394
|
+
case "m":
|
|
1395
|
+
return String(u2);
|
|
1396
|
+
case "mm":
|
|
1397
|
+
return b.s(u2, 2, "0");
|
|
1398
|
+
case "s":
|
|
1399
|
+
return String(e2.$s);
|
|
1400
|
+
case "ss":
|
|
1401
|
+
return b.s(e2.$s, 2, "0");
|
|
1402
|
+
case "SSS":
|
|
1403
|
+
return b.s(e2.$ms, 3, "0");
|
|
1404
|
+
case "Z":
|
|
1405
|
+
return i2;
|
|
1406
|
+
}
|
|
1407
|
+
return null;
|
|
1408
|
+
}(t3) || i2.replace(":", "");
|
|
1409
|
+
});
|
|
1410
|
+
}, m2.utcOffset = function() {
|
|
1411
|
+
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
1412
|
+
}, m2.diff = function(r2, d2, l2) {
|
|
1413
|
+
var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = /* @__PURE__ */ __name(function() {
|
|
1414
|
+
return b.m(y2, m3);
|
|
1415
|
+
}, "D");
|
|
1416
|
+
switch (M3) {
|
|
1417
|
+
case h:
|
|
1418
|
+
$2 = D2() / 12;
|
|
1419
|
+
break;
|
|
1420
|
+
case c:
|
|
1421
|
+
$2 = D2();
|
|
1422
|
+
break;
|
|
1423
|
+
case f:
|
|
1424
|
+
$2 = D2() / 3;
|
|
1425
|
+
break;
|
|
1426
|
+
case o:
|
|
1427
|
+
$2 = (g2 - v2) / 6048e5;
|
|
1428
|
+
break;
|
|
1429
|
+
case a:
|
|
1430
|
+
$2 = (g2 - v2) / 864e5;
|
|
1431
|
+
break;
|
|
1432
|
+
case u:
|
|
1433
|
+
$2 = g2 / n;
|
|
1434
|
+
break;
|
|
1435
|
+
case s:
|
|
1436
|
+
$2 = g2 / e;
|
|
1437
|
+
break;
|
|
1438
|
+
case i:
|
|
1439
|
+
$2 = g2 / t;
|
|
1440
|
+
break;
|
|
1441
|
+
default:
|
|
1442
|
+
$2 = g2;
|
|
1443
|
+
}
|
|
1444
|
+
return l2 ? $2 : b.a($2);
|
|
1445
|
+
}, m2.daysInMonth = function() {
|
|
1446
|
+
return this.endOf(c).$D;
|
|
1447
|
+
}, m2.$locale = function() {
|
|
1448
|
+
return D[this.$L];
|
|
1449
|
+
}, m2.locale = function(t2, e2) {
|
|
1450
|
+
if (!t2) return this.$L;
|
|
1451
|
+
var n2 = this.clone(), r2 = w(t2, e2, !0);
|
|
1452
|
+
return r2 && (n2.$L = r2), n2;
|
|
1453
|
+
}, m2.clone = function() {
|
|
1454
|
+
return b.w(this.$d, this);
|
|
1455
|
+
}, m2.toDate = function() {
|
|
1456
|
+
return new Date(this.valueOf());
|
|
1457
|
+
}, m2.toJSON = function() {
|
|
1458
|
+
return this.isValid() ? this.toISOString() : null;
|
|
1459
|
+
}, m2.toISOString = function() {
|
|
1460
|
+
return this.$d.toISOString();
|
|
1461
|
+
}, m2.toString = function() {
|
|
1462
|
+
return this.$d.toUTCString();
|
|
1463
|
+
}, M2;
|
|
1464
|
+
}(), k = _.prototype;
|
|
1465
|
+
return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
|
|
1466
|
+
k[t2[1]] = function(e2) {
|
|
1467
|
+
return this.$g(e2, t2[0], t2[1]);
|
|
1468
|
+
};
|
|
1469
|
+
}), O.extend = function(t2, e2) {
|
|
1470
|
+
return t2.$i || (t2(e2, _, O), t2.$i = !0), O;
|
|
1471
|
+
}, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
|
|
1472
|
+
return O(1e3 * t2);
|
|
1473
|
+
}, O.en = D[g], O.Ls = D, O.p = {}, O;
|
|
1474
|
+
});
|
|
1475
|
+
})(dayjs_min);
|
|
1476
|
+
var dayjs_minExports = dayjs_min.exports;
|
|
1477
|
+
const dayjs = /* @__PURE__ */ getDefaultExportFromCjs(dayjs_minExports), DateOperatorNameMap = {
|
|
1478
|
+
[DataValidationOperator.BETWEEN]: "dataValidation.date.operators.between",
|
|
1479
|
+
[DataValidationOperator.EQUAL]: "dataValidation.date.operators.equal",
|
|
1480
|
+
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
|
|
1481
|
+
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
|
|
1482
|
+
[DataValidationOperator.LESS_THAN]: "dataValidation.date.operators.lessThan",
|
|
1483
|
+
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
|
|
1484
|
+
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
|
|
1485
|
+
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
|
|
1486
|
+
};
|
|
1487
|
+
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 + "";
|
|
1488
|
+
const DateOperatorTitleMap = {
|
|
1489
|
+
[DataValidationOperator.BETWEEN]: "dataValidation.date.ruleName.between",
|
|
1490
|
+
[DataValidationOperator.EQUAL]: "dataValidation.date.ruleName.equal",
|
|
1491
|
+
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
|
|
1492
|
+
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
|
|
1493
|
+
[DataValidationOperator.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
|
|
1494
|
+
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
|
|
1495
|
+
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
|
|
1496
|
+
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
|
|
1497
|
+
}, DateOperatorErrorTitleMap = {
|
|
1498
|
+
[DataValidationOperator.BETWEEN]: "dataValidation.date.errorMsg.between",
|
|
1499
|
+
[DataValidationOperator.EQUAL]: "dataValidation.date.errorMsg.equal",
|
|
1500
|
+
[DataValidationOperator.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
|
|
1501
|
+
[DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
|
|
1502
|
+
[DataValidationOperator.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
|
|
1503
|
+
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
|
|
1504
|
+
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
|
|
1505
|
+
[DataValidationOperator.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
|
|
1506
|
+
}, TWO_FORMULA_OPERATOR_COUNT = [
|
|
1507
|
+
DataValidationOperator.BETWEEN,
|
|
1508
|
+
DataValidationOperator.NOT_BETWEEN
|
|
1509
|
+
];
|
|
1510
|
+
function isBlankCell(cellData) {
|
|
1511
|
+
var _a7, _b;
|
|
1512
|
+
return cellData ? cellData.p ? !((_b = (_a7 = cellData.p.body) == null ? void 0 : _a7.dataStream) != null ? _b : "").slice(0, -2).trim() : Tools.isBlank(cellData.v) : !0;
|
|
1513
|
+
}
|
|
1514
|
+
__name(isBlankCell, "isBlankCell");
|
|
1515
|
+
function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, source = "command", fillDefaultValue = !0) {
|
|
1516
|
+
const lexerTreeBuilder = accessor.get(LexerTreeBuilder), redoMutations = [], undoMutations = [], sheetDataValidationModel = accessor.get(SheetDataValidationModel), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
|
|
1517
|
+
if (!target)
|
|
1518
|
+
return {
|
|
1519
|
+
redoMutations,
|
|
1520
|
+
undoMutations
|
|
1521
|
+
};
|
|
1522
|
+
const { worksheet } = target, redoMatrix = new ObjectMatrix();
|
|
1523
|
+
function setRangesDefaultValue(ranges, defaultValue) {
|
|
1524
|
+
fillDefaultValue && ranges.forEach((range) => {
|
|
1525
|
+
Range.foreach(range, (row, column) => {
|
|
1526
|
+
const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
|
|
1527
|
+
(isBlankCell(cellData) || value === defaultValue) && redoMatrix.setValue(row, column, {
|
|
1528
|
+
v: defaultValue,
|
|
1529
|
+
p: null
|
|
1530
|
+
});
|
|
1531
|
+
});
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
__name(setRangesDefaultValue, "setRangesDefaultValue"), diffs.forEach((diff) => {
|
|
1535
|
+
switch (diff.type) {
|
|
1536
|
+
case "delete":
|
|
1537
|
+
redoMutations.push({
|
|
1538
|
+
id: RemoveDataValidationMutation.id,
|
|
1539
|
+
params: {
|
|
1540
|
+
unitId,
|
|
1541
|
+
subUnitId,
|
|
1542
|
+
ruleId: diff.rule.uid,
|
|
1543
|
+
source
|
|
1544
|
+
}
|
|
1545
|
+
}), undoMutations.unshift({
|
|
1546
|
+
id: AddDataValidationMutation.id,
|
|
1547
|
+
params: {
|
|
1548
|
+
unitId,
|
|
1549
|
+
subUnitId,
|
|
1550
|
+
rule: diff.rule,
|
|
1551
|
+
index: diff.index,
|
|
1552
|
+
source
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1555
|
+
break;
|
|
1556
|
+
case "update": {
|
|
1557
|
+
if (redoMutations.push({
|
|
1558
|
+
id: UpdateDataValidationMutation.id,
|
|
1559
|
+
params: {
|
|
1560
|
+
unitId,
|
|
1561
|
+
subUnitId,
|
|
1562
|
+
ruleId: diff.ruleId,
|
|
1563
|
+
payload: {
|
|
1564
|
+
type: UpdateRuleType.RANGE,
|
|
1565
|
+
payload: diff.newRanges
|
|
1566
|
+
},
|
|
1567
|
+
source
|
|
1568
|
+
}
|
|
1569
|
+
}), undoMutations.unshift({
|
|
1570
|
+
id: UpdateDataValidationMutation.id,
|
|
1571
|
+
params: {
|
|
1572
|
+
unitId,
|
|
1573
|
+
subUnitId,
|
|
1574
|
+
ruleId: diff.ruleId,
|
|
1575
|
+
payload: {
|
|
1576
|
+
type: UpdateRuleType.RANGE,
|
|
1577
|
+
payload: diff.oldRanges
|
|
1578
|
+
},
|
|
1579
|
+
source
|
|
1580
|
+
}
|
|
1581
|
+
}), diff.rule.type === DataValidationType.CUSTOM) {
|
|
1582
|
+
const originRow = diff.oldRanges[0].startRow, originColumn = diff.oldRanges[0].startColumn, newRow = diff.newRanges[0].startRow, newColumn = diff.newRanges[0].startColumn, rowDiff = newRow - originRow, columnDiff = newColumn - originColumn, newFormula = lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula1, columnDiff, rowDiff);
|
|
1583
|
+
newFormula !== diff.rule.formula1 && (redoMutations.push({
|
|
1584
|
+
id: UpdateDataValidationMutation.id,
|
|
1585
|
+
params: {
|
|
1586
|
+
unitId,
|
|
1587
|
+
subUnitId,
|
|
1588
|
+
ruleId: diff.ruleId,
|
|
1589
|
+
payload: {
|
|
1590
|
+
type: UpdateRuleType.SETTING,
|
|
1591
|
+
payload: {
|
|
1592
|
+
...getRuleSetting(diff.rule),
|
|
1593
|
+
formula1: newFormula
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
}), undoMutations.unshift({
|
|
1598
|
+
id: UpdateDataValidationMutation.id,
|
|
1599
|
+
params: {
|
|
1600
|
+
unitId,
|
|
1601
|
+
subUnitId,
|
|
1602
|
+
ruleId: diff.ruleId,
|
|
1603
|
+
payload: {
|
|
1604
|
+
type: UpdateRuleType.SETTING,
|
|
1605
|
+
payload: getRuleSetting(diff.rule)
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}));
|
|
1609
|
+
}
|
|
1610
|
+
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, diff.ruleId);
|
|
1611
|
+
if (rule && rule.type === DataValidationType.CHECKBOX) {
|
|
1612
|
+
const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(rule, unitId, subUnitId);
|
|
1613
|
+
setRangesDefaultValue(diff.newRanges, formula.formula2);
|
|
1614
|
+
}
|
|
1615
|
+
break;
|
|
1616
|
+
}
|
|
1617
|
+
case "add": {
|
|
1618
|
+
if (redoMutations.push({
|
|
1619
|
+
id: AddDataValidationMutation.id,
|
|
1620
|
+
params: {
|
|
1621
|
+
unitId,
|
|
1622
|
+
subUnitId,
|
|
1623
|
+
rule: diff.rule,
|
|
1624
|
+
source
|
|
1625
|
+
}
|
|
1626
|
+
}), undoMutations.unshift({
|
|
1627
|
+
id: RemoveDataValidationMutation.id,
|
|
1628
|
+
params: {
|
|
1629
|
+
unitId,
|
|
1630
|
+
subUnitId,
|
|
1631
|
+
ruleId: diff.rule.uid,
|
|
1632
|
+
source
|
|
1633
|
+
}
|
|
1634
|
+
}), diff.rule.type === DataValidationType.CHECKBOX) {
|
|
1635
|
+
const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
|
|
1636
|
+
setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
|
|
1637
|
+
}
|
|
1638
|
+
break;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
const redoSetRangeValues = {
|
|
1643
|
+
id: SetRangeValuesMutation.id,
|
|
1644
|
+
params: {
|
|
1645
|
+
unitId,
|
|
1646
|
+
subUnitId,
|
|
1647
|
+
cellValue: redoMatrix.getData()
|
|
1648
|
+
}
|
|
1649
|
+
}, undoSetRangeValues = {
|
|
1650
|
+
id: SetRangeValuesMutation.id,
|
|
1651
|
+
params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
|
|
1652
|
+
};
|
|
1653
|
+
return redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues), {
|
|
1654
|
+
redoMutations,
|
|
1655
|
+
undoMutations
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
__name(getDataValidationDiffMutations, "getDataValidationDiffMutations");
|
|
1659
|
+
const UpdateSheetDataValidationRangeCommand = {
|
|
1660
|
+
type: CommandType.COMMAND,
|
|
1661
|
+
id: "sheet.command.updateDataValidationRuleRange",
|
|
1662
|
+
handler(accessor, params) {
|
|
1663
|
+
if (!params)
|
|
1664
|
+
return !1;
|
|
1665
|
+
const { unitId, subUnitId, ranges, ruleId } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService);
|
|
1666
|
+
if (!sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId))
|
|
1667
|
+
return !1;
|
|
1668
|
+
const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1669
|
+
matrix.updateRange(ruleId, ranges);
|
|
1670
|
+
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
1671
|
+
return undoRedoService.pushUndoRedo({
|
|
1672
|
+
undoMutations,
|
|
1673
|
+
redoMutations,
|
|
1674
|
+
unitID: unitId
|
|
1675
|
+
}), sequenceExecute(redoMutations, commandService), !0;
|
|
1676
|
+
}
|
|
1677
|
+
}, AddSheetDataValidationCommand = {
|
|
1678
|
+
type: CommandType.COMMAND,
|
|
1679
|
+
id: "sheet.command.addDataValidation",
|
|
1680
|
+
handler(accessor, params) {
|
|
1681
|
+
if (!params)
|
|
1682
|
+
return !1;
|
|
1683
|
+
const { unitId, subUnitId, rule } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1684
|
+
matrix.addRule(rule);
|
|
1685
|
+
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), mutationParams = {
|
|
1686
|
+
unitId,
|
|
1687
|
+
subUnitId,
|
|
1688
|
+
rule
|
|
1689
|
+
}, { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
1690
|
+
return redoMutations.push({
|
|
1691
|
+
id: AddDataValidationMutation.id,
|
|
1692
|
+
params: mutationParams
|
|
1693
|
+
}), undoMutations.unshift({
|
|
1694
|
+
id: RemoveDataValidationMutation.id,
|
|
1695
|
+
params: {
|
|
1696
|
+
unitId,
|
|
1697
|
+
subUnitId,
|
|
1698
|
+
ruleId: rule.uid
|
|
1699
|
+
}
|
|
1700
|
+
}), undoRedoService.pushUndoRedo({
|
|
1701
|
+
unitID: unitId,
|
|
1702
|
+
redoMutations,
|
|
1703
|
+
undoMutations
|
|
1704
|
+
}), sequenceExecute(redoMutations, commandService), !0;
|
|
1705
|
+
}
|
|
1706
|
+
}, UpdateSheetDataValidationSettingCommand = {
|
|
1707
|
+
type: CommandType.COMMAND,
|
|
1708
|
+
id: "sheets.command.update-data-validation-setting",
|
|
1709
|
+
// eslint-disable-next-line max-lines-per-function
|
|
1710
|
+
handler(accessor, params) {
|
|
1711
|
+
if (!params)
|
|
1712
|
+
return !1;
|
|
1713
|
+
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);
|
|
1714
|
+
if (!validator)
|
|
1715
|
+
return !1;
|
|
1716
|
+
const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1717
|
+
if (!rule)
|
|
1718
|
+
return !1;
|
|
1719
|
+
const newRule = { ...rule, ...setting };
|
|
1720
|
+
if (!validator.validatorFormula(newRule, unitId, subUnitId).success)
|
|
1721
|
+
return !1;
|
|
1722
|
+
const mutationParams = {
|
|
1723
|
+
unitId,
|
|
1724
|
+
subUnitId,
|
|
1725
|
+
ruleId,
|
|
1726
|
+
payload: {
|
|
1727
|
+
type: UpdateRuleType.SETTING,
|
|
1728
|
+
payload: {
|
|
1729
|
+
...setting,
|
|
1730
|
+
...validator.normalizeFormula(newRule, unitId, subUnitId)
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}, redoMutations = [{
|
|
1734
|
+
id: UpdateDataValidationMutation.id,
|
|
1735
|
+
params: mutationParams
|
|
1736
|
+
}], undoMutationParams = {
|
|
1737
|
+
unitId,
|
|
1738
|
+
subUnitId,
|
|
1739
|
+
ruleId,
|
|
1740
|
+
payload: {
|
|
1741
|
+
type: UpdateRuleType.SETTING,
|
|
1742
|
+
payload: getRuleSetting(rule)
|
|
1743
|
+
}
|
|
1744
|
+
}, undoMutations = [{
|
|
1745
|
+
id: UpdateDataValidationMutation.id,
|
|
1746
|
+
params: undoMutationParams
|
|
1747
|
+
}];
|
|
1748
|
+
if (setting.type === DataValidationType.CHECKBOX) {
|
|
1749
|
+
const ranges = rule.ranges, univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
|
|
1750
|
+
if (target) {
|
|
1751
|
+
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;
|
|
1752
|
+
ranges.forEach((range) => {
|
|
1753
|
+
Range.foreach(range, (row, column) => {
|
|
1754
|
+
const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
|
|
1755
|
+
isBlankCell(cellData) || value === String(oldFormula2) ? redoMatrix.setValue(row, column, {
|
|
1756
|
+
v: formula2,
|
|
1757
|
+
p: null
|
|
1758
|
+
}) : value === String(oldFormula1) && redoMatrix.setValue(row, column, {
|
|
1759
|
+
v: formula1,
|
|
1760
|
+
p: null
|
|
1761
|
+
});
|
|
1762
|
+
});
|
|
1763
|
+
});
|
|
1764
|
+
const redoSetRangeValues = {
|
|
1765
|
+
id: SetRangeValuesMutation.id,
|
|
1766
|
+
params: {
|
|
1767
|
+
unitId,
|
|
1768
|
+
subUnitId,
|
|
1769
|
+
cellValue: redoMatrix.getData()
|
|
1770
|
+
}
|
|
1771
|
+
}, undoSetRangeValues = {
|
|
1772
|
+
id: SetRangeValuesMutation.id,
|
|
1773
|
+
params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
|
|
1774
|
+
};
|
|
1775
|
+
redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
return sequenceExecute(redoMutations, commandService).result ? (redoUndoService.pushUndoRedo({
|
|
1779
|
+
unitID: unitId,
|
|
1780
|
+
redoMutations,
|
|
1781
|
+
undoMutations
|
|
1782
|
+
}), !0) : !1;
|
|
1783
|
+
}
|
|
1784
|
+
}, UpdateSheetDataValidationOptionsCommand = {
|
|
1785
|
+
type: CommandType.COMMAND,
|
|
1786
|
+
id: "sheets.command.update-data-validation-options",
|
|
1787
|
+
handler(accessor, params) {
|
|
1788
|
+
if (!params)
|
|
1789
|
+
return !1;
|
|
1790
|
+
const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, options } = params, rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
1791
|
+
if (!rule)
|
|
1792
|
+
return !1;
|
|
1793
|
+
const mutationParams = {
|
|
1794
|
+
unitId,
|
|
1795
|
+
subUnitId,
|
|
1796
|
+
ruleId,
|
|
1797
|
+
payload: {
|
|
1798
|
+
type: UpdateRuleType.OPTIONS,
|
|
1799
|
+
payload: options
|
|
1800
|
+
}
|
|
1801
|
+
}, redoMutations = [{
|
|
1802
|
+
id: UpdateDataValidationMutation.id,
|
|
1803
|
+
params: mutationParams
|
|
1804
|
+
}], undoMutationParams = {
|
|
1805
|
+
unitId,
|
|
1806
|
+
subUnitId,
|
|
1807
|
+
ruleId,
|
|
1808
|
+
payload: {
|
|
1809
|
+
type: UpdateRuleType.OPTIONS,
|
|
1810
|
+
payload: getRuleOptions(rule)
|
|
1811
|
+
}
|
|
1812
|
+
}, undoMutations = [{
|
|
1813
|
+
id: UpdateDataValidationMutation.id,
|
|
1814
|
+
params: undoMutationParams
|
|
1815
|
+
}];
|
|
1816
|
+
return redoUndoService.pushUndoRedo({
|
|
1817
|
+
unitID: unitId,
|
|
1818
|
+
redoMutations,
|
|
1819
|
+
undoMutations
|
|
1820
|
+
}), commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams), !0;
|
|
1821
|
+
}
|
|
1822
|
+
}, ClearRangeDataValidationCommand = {
|
|
1823
|
+
type: CommandType.COMMAND,
|
|
1824
|
+
id: "sheets.command.clear-range-data-validation",
|
|
1825
|
+
handler(accessor, params) {
|
|
1826
|
+
if (!params)
|
|
1827
|
+
return !1;
|
|
1828
|
+
const { unitId, subUnitId, ranges } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId }), sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1829
|
+
if (!target) return !1;
|
|
1830
|
+
const undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
1831
|
+
matrix.removeRange(ranges);
|
|
1832
|
+
const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
|
|
1833
|
+
return undoRedoService.pushUndoRedo({
|
|
1834
|
+
unitID: unitId,
|
|
1835
|
+
redoMutations,
|
|
1836
|
+
undoMutations
|
|
1837
|
+
}), sequenceExecute(redoMutations, commandService).result;
|
|
1838
|
+
}
|
|
1839
|
+
}, RemoveSheetAllDataValidationCommand = {
|
|
1840
|
+
type: CommandType.COMMAND,
|
|
1841
|
+
id: "sheet.command.remove-all-data-validation",
|
|
1842
|
+
handler(accessor, params) {
|
|
1843
|
+
if (!params)
|
|
1844
|
+
return !1;
|
|
1845
|
+
const { unitId, subUnitId } = params, commandService = accessor.get(ICommandService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), undoRedoService = accessor.get(IUndoRedoService), currentRules = [...sheetDataValidationModel.getRules(unitId, subUnitId)], redoParams = {
|
|
1846
|
+
unitId,
|
|
1847
|
+
subUnitId,
|
|
1848
|
+
ruleId: currentRules.map((rule) => rule.uid)
|
|
1849
|
+
}, redoMutations = [{
|
|
1850
|
+
id: RemoveDataValidationMutation.id,
|
|
1851
|
+
params: redoParams
|
|
1852
|
+
}], undoMutations = [{
|
|
1853
|
+
id: AddDataValidationMutation.id,
|
|
1854
|
+
params: {
|
|
1855
|
+
unitId,
|
|
1856
|
+
subUnitId,
|
|
1857
|
+
rule: currentRules
|
|
1858
|
+
}
|
|
1859
|
+
}];
|
|
1860
|
+
return undoRedoService.pushUndoRedo({
|
|
1861
|
+
redoMutations,
|
|
1862
|
+
undoMutations,
|
|
1863
|
+
unitID: unitId
|
|
1864
|
+
}), commandService.executeCommand(RemoveDataValidationMutation.id, redoParams), !0;
|
|
1865
|
+
}
|
|
1866
|
+
}, removeDataValidationUndoFactory = /* @__PURE__ */ __name((accessor, redoParams) => {
|
|
1867
|
+
const sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, source } = redoParams;
|
|
1868
|
+
if (Array.isArray(ruleId)) {
|
|
1869
|
+
const rules = ruleId.map((id) => sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
1870
|
+
return [{
|
|
1871
|
+
id: AddDataValidationMutation.id,
|
|
1872
|
+
params: {
|
|
1873
|
+
unitId,
|
|
1874
|
+
subUnitId,
|
|
1875
|
+
rule: rules,
|
|
1876
|
+
source
|
|
1877
|
+
}
|
|
1878
|
+
}];
|
|
1879
|
+
}
|
|
1880
|
+
return [{
|
|
1881
|
+
id: AddDataValidationMutation.id,
|
|
1882
|
+
params: {
|
|
1883
|
+
unitId,
|
|
1884
|
+
subUnitId,
|
|
1885
|
+
rule: {
|
|
1886
|
+
...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
|
|
1887
|
+
},
|
|
1888
|
+
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
1889
|
+
}
|
|
1890
|
+
}];
|
|
1891
|
+
}, "removeDataValidationUndoFactory"), RemoveSheetDataValidationCommand = {
|
|
1892
|
+
type: CommandType.COMMAND,
|
|
1893
|
+
id: "sheet.command.remove-data-validation-rule",
|
|
1894
|
+
handler(accessor, params) {
|
|
1895
|
+
if (!params)
|
|
1896
|
+
return !1;
|
|
1897
|
+
const { unitId, subUnitId, ruleId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), redoMutations = [{
|
|
1898
|
+
id: RemoveDataValidationMutation.id,
|
|
1899
|
+
params
|
|
1900
|
+
}], undoMutations = [{
|
|
1901
|
+
id: AddDataValidationMutation.id,
|
|
1902
|
+
params: {
|
|
1903
|
+
unitId,
|
|
1904
|
+
subUnitId,
|
|
1905
|
+
rule: {
|
|
1906
|
+
...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
|
|
1907
|
+
},
|
|
1908
|
+
index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
1909
|
+
}
|
|
1910
|
+
}];
|
|
1911
|
+
return undoRedoService.pushUndoRedo({
|
|
1912
|
+
undoMutations,
|
|
1913
|
+
redoMutations,
|
|
1914
|
+
unitID: params.unitId
|
|
1915
|
+
}), commandService.executeCommand(RemoveDataValidationMutation.id, params), !0;
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1919
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1920
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1921
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
1922
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a6;
|
|
1923
|
+
let SheetsDataValidationValidatorService = (_a6 = class extends Disposable {
|
|
1924
|
+
constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
|
|
1925
|
+
super(), this._univerInstanceService = _univerInstanceService, this._sheetDataValidationModel = _sheetDataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._lifecycleService = _lifecycleService, this._initRecalculate();
|
|
1926
|
+
}
|
|
1927
|
+
_initRecalculate() {
|
|
1928
|
+
const handleDirtyRanges = /* @__PURE__ */ __name((ranges) => {
|
|
1929
|
+
if (ranges.length === 0)
|
|
1930
|
+
return;
|
|
1931
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), worksheet = workbook == null ? void 0 : workbook.getActiveSheet(), map = {};
|
|
1932
|
+
ranges.flat().forEach((range) => {
|
|
1933
|
+
map[range.unitId] || (map[range.unitId] = {}), map[range.unitId][range.subUnitId] || (map[range.unitId][range.subUnitId] = []);
|
|
1934
|
+
const workbook2 = this._univerInstanceService.getUnit(range.unitId, UniverInstanceType.UNIVER_SHEET), worksheet2 = workbook2 == null ? void 0 : workbook2.getSheetBySheetId(range.subUnitId);
|
|
1935
|
+
worksheet2 && map[range.unitId][range.subUnitId].push(...range.ranges.map((range2) => Range.transformRange(range2, worksheet2)));
|
|
1936
|
+
}), Object.entries(map).forEach(([unitId, subUnitMap]) => {
|
|
1937
|
+
Object.entries(subUnitMap).forEach(([subUnitId, ranges2]) => {
|
|
1938
|
+
(workbook == null ? void 0 : workbook.getUnitId()) === unitId && (worksheet == null ? void 0 : worksheet.getSheetId()) === subUnitId ? this.validatorRanges(unitId, subUnitId, ranges2) : requestIdleCallback(() => {
|
|
1939
|
+
this.validatorRanges(unitId, subUnitId, ranges2);
|
|
1940
|
+
});
|
|
1941
|
+
});
|
|
1942
|
+
});
|
|
1943
|
+
}, "handleDirtyRanges");
|
|
1944
|
+
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));
|
|
1945
|
+
}
|
|
1946
|
+
async validatorCell(unitId, subUnitId, row, col) {
|
|
1947
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
1948
|
+
if (!workbook)
|
|
1949
|
+
throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
1950
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
1951
|
+
if (!worksheet)
|
|
1952
|
+
throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
1953
|
+
if (!Tools.isDefine(row) || !Tools.isDefine(col))
|
|
1954
|
+
throw new Error(`row or col is not defined, row: ${row}, col: ${col}`);
|
|
1955
|
+
const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
|
|
1956
|
+
return rule ? new Promise((resolve) => {
|
|
1957
|
+
this._sheetDataValidationModel.validator(rule, { unitId, subUnitId, row, col, worksheet, workbook }, (status) => {
|
|
1958
|
+
resolve(status);
|
|
1959
|
+
});
|
|
1960
|
+
}) : DataValidationStatus.VALID;
|
|
1961
|
+
}
|
|
1962
|
+
validatorRanges(unitId, subUnitId, ranges) {
|
|
1963
|
+
return Promise.all(ranges.map((range) => {
|
|
1964
|
+
const promises = [];
|
|
1965
|
+
return Range.foreach(range, (row, col) => {
|
|
1966
|
+
promises.push(this.validatorCell(unitId, subUnitId, row, col));
|
|
1967
|
+
}), promises;
|
|
1968
|
+
}));
|
|
1969
|
+
}
|
|
1970
|
+
async validatorWorksheet(unitId, subUnitId) {
|
|
1971
|
+
const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
|
|
1972
|
+
return await Promise.all(rules.map((rule) => Promise.all(rule.ranges.map((range) => {
|
|
1973
|
+
const promises = [];
|
|
1974
|
+
return Range.foreach(range, (row, col) => {
|
|
1975
|
+
promises.push(this.validatorCell(unitId, subUnitId, row, col));
|
|
1976
|
+
}), promises;
|
|
1977
|
+
})))), this._dataValidationCacheService.ensureCache(unitId, subUnitId);
|
|
1978
|
+
}
|
|
1979
|
+
async validatorWorkbook(unitId) {
|
|
1980
|
+
const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId), results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id))), map = {};
|
|
1981
|
+
return results.forEach((result, i) => {
|
|
1982
|
+
map[sheetIds[i]] = result;
|
|
1983
|
+
}), map;
|
|
1984
|
+
}
|
|
1985
|
+
getDataValidations(unitId, subUnitId, ranges) {
|
|
1986
|
+
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId), ruleIdSet = /* @__PURE__ */ new Set();
|
|
1987
|
+
return ranges.forEach((range) => {
|
|
1988
|
+
Range.foreach(range, (row, col) => {
|
|
1989
|
+
const ruleId = ruleMatrix.getValue(row, col);
|
|
1990
|
+
ruleId && ruleIdSet.add(ruleId);
|
|
1991
|
+
});
|
|
1992
|
+
}), Array.from(ruleIdSet).map((id) => this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
1993
|
+
}
|
|
1994
|
+
getDataValidation(unitId, subUnitId, ranges) {
|
|
1995
|
+
return this.getDataValidations(unitId, subUnitId, ranges)[0];
|
|
1996
|
+
}
|
|
1997
|
+
}, __name(_a6, "SheetsDataValidationValidatorService"), _a6);
|
|
1998
|
+
SheetsDataValidationValidatorService = __decorateClass([
|
|
1999
|
+
__decorateParam(0, IUniverInstanceService),
|
|
2000
|
+
__decorateParam(1, Inject(SheetDataValidationModel)),
|
|
2001
|
+
__decorateParam(2, Inject(DataValidationCacheService)),
|
|
2002
|
+
__decorateParam(3, Inject(LifecycleService))
|
|
2003
|
+
], SheetsDataValidationValidatorService);
|
|
2004
|
+
export {
|
|
2005
|
+
AddSheetDataValidationCommand as A,
|
|
2006
|
+
CheckboxValidator as C,
|
|
2007
|
+
DataValidationFormulaService as D,
|
|
2008
|
+
RemoveSheetDataValidationCommand as R,
|
|
2009
|
+
SheetDataValidationModel as S,
|
|
2010
|
+
TWO_FORMULA_OPERATOR_COUNT as T,
|
|
2011
|
+
UpdateSheetDataValidationRangeCommand as U,
|
|
2012
|
+
DateOperatorNameMap as a,
|
|
2013
|
+
DateOperatorTitleMap as b,
|
|
2014
|
+
DateOperatorErrorTitleMap as c,
|
|
2015
|
+
dayjs as d,
|
|
2016
|
+
getCellValueOrigin as e,
|
|
2017
|
+
DataValidationCustomFormulaService as f,
|
|
2018
|
+
getFormulaResult as g,
|
|
2019
|
+
getFormulaCellData as h,
|
|
2020
|
+
isLegalFormulaResult as i,
|
|
2021
|
+
getDataValidationDiffMutations as j,
|
|
2022
|
+
DataValidationCacheService as k,
|
|
2023
|
+
SheetsDataValidationValidatorService as l,
|
|
2024
|
+
UpdateSheetDataValidationSettingCommand as m,
|
|
2025
|
+
UpdateSheetDataValidationOptionsCommand as n,
|
|
2026
|
+
RemoveSheetAllDataValidationCommand as o,
|
|
2027
|
+
ClearRangeDataValidationCommand as p,
|
|
2028
|
+
CHECKBOX_FORMULA_1 as q,
|
|
2029
|
+
removeDataValidationUndoFactory as r,
|
|
2030
|
+
CHECKBOX_FORMULA_2 as s,
|
|
2031
|
+
transformCheckboxValue as t
|
|
2032
|
+
};
|