@univerjs/sheets-conditional-formatting 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -21
- package/lib/cjs/facade.js +4 -4
- package/lib/cjs/index.js +118 -125
- package/lib/es/facade.js +4 -4
- package/lib/es/index.js +118 -125
- package/lib/facade.js +4 -4
- package/lib/index.js +118 -125
- package/lib/umd/index.js +1 -1
- package/package.json +15 -11
package/lib/cjs/index.js
CHANGED
|
@@ -79,37 +79,37 @@ const createDefaultRule = () => ({
|
|
|
79
79
|
ranges: [],
|
|
80
80
|
stopIfTrue: false,
|
|
81
81
|
rule: {
|
|
82
|
-
type:
|
|
83
|
-
subType:
|
|
84
|
-
operator:
|
|
82
|
+
type: "highlightCell",
|
|
83
|
+
subType: "text",
|
|
84
|
+
operator: "containsText"
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
const createDefaultValue = (subType, operator) => {
|
|
88
88
|
switch (subType) {
|
|
89
|
-
case
|
|
89
|
+
case "text":
|
|
90
90
|
if ([
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
"beginsWith",
|
|
92
|
+
"containsText",
|
|
93
|
+
"endsWith",
|
|
94
|
+
"equal",
|
|
95
|
+
"notContainsText",
|
|
96
|
+
"notEqual"
|
|
97
97
|
].includes(operator)) return "";
|
|
98
98
|
break;
|
|
99
|
-
case
|
|
100
|
-
if ([
|
|
99
|
+
case "number":
|
|
100
|
+
if (["between", "notBetween"].includes(operator)) return [10, 100];
|
|
101
101
|
return 10;
|
|
102
102
|
}
|
|
103
103
|
return "";
|
|
104
104
|
};
|
|
105
105
|
const createDefaultValueByValueType = (type, defaultValue) => {
|
|
106
106
|
switch (type) {
|
|
107
|
-
case
|
|
108
|
-
case
|
|
109
|
-
case
|
|
110
|
-
case
|
|
111
|
-
case
|
|
112
|
-
case
|
|
107
|
+
case "formula": return "=";
|
|
108
|
+
case "max":
|
|
109
|
+
case "min": return "";
|
|
110
|
+
case "percent":
|
|
111
|
+
case "percentile":
|
|
112
|
+
case "num": return defaultValue !== void 0 ? defaultValue : 10;
|
|
113
113
|
}
|
|
114
114
|
return "";
|
|
115
115
|
};
|
|
@@ -221,7 +221,7 @@ const isAnchorEqual = (anchor1, anchor2) => {
|
|
|
221
221
|
const createCfId = () => `${(0, _univerjs_core.generateRandomId)(8)}`;
|
|
222
222
|
|
|
223
223
|
//#endregion
|
|
224
|
-
//#region \0@oxc-project+runtime@0.
|
|
224
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
225
225
|
function _typeof(o) {
|
|
226
226
|
"@babel/helpers - typeof";
|
|
227
227
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -232,7 +232,7 @@ function _typeof(o) {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
//#endregion
|
|
235
|
-
//#region \0@oxc-project+runtime@0.
|
|
235
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
236
236
|
function toPrimitive(t, r) {
|
|
237
237
|
if ("object" != _typeof(t) || !t) return t;
|
|
238
238
|
var e = t[Symbol.toPrimitive];
|
|
@@ -245,14 +245,14 @@ function toPrimitive(t, r) {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
//#endregion
|
|
248
|
-
//#region \0@oxc-project+runtime@0.
|
|
248
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
249
249
|
function toPropertyKey(t) {
|
|
250
250
|
var i = toPrimitive(t, "string");
|
|
251
251
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
//#endregion
|
|
255
|
-
//#region \0@oxc-project+runtime@0.
|
|
255
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
256
256
|
function _defineProperty(e, r, t) {
|
|
257
257
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
258
258
|
value: t,
|
|
@@ -751,7 +751,7 @@ const SetCfCommand = {
|
|
|
751
751
|
};
|
|
752
752
|
|
|
753
753
|
//#endregion
|
|
754
|
-
//#region \0@oxc-project+runtime@0.
|
|
754
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
|
|
755
755
|
function __decorateParam(paramIndex, decorator) {
|
|
756
756
|
return function(target, key) {
|
|
757
757
|
decorator(target, key, paramIndex);
|
|
@@ -759,7 +759,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
759
759
|
}
|
|
760
760
|
|
|
761
761
|
//#endregion
|
|
762
|
-
//#region \0@oxc-project+runtime@0.
|
|
762
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
|
|
763
763
|
function __decorate(decorators, target, key, desc) {
|
|
764
764
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
765
765
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -783,9 +783,9 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
|
|
|
783
783
|
_initRuleChange() {
|
|
784
784
|
const isNeedMarkFormulaDirty = (rule) => {
|
|
785
785
|
switch (rule.type) {
|
|
786
|
-
case
|
|
787
|
-
case
|
|
788
|
-
case
|
|
786
|
+
case "colorScale": return rule.config.some((item) => item.value.type === "formula");
|
|
787
|
+
case "dataBar": return [rule.config.max, rule.config.min].some((item) => item.type === "formula");
|
|
788
|
+
case "iconSet": return rule.config.some((item) => item.value.type === "formula");
|
|
789
789
|
}
|
|
790
790
|
};
|
|
791
791
|
this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.subscribe((option) => {
|
|
@@ -802,8 +802,8 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
|
|
|
802
802
|
*/
|
|
803
803
|
_registerRuleFormulas(unitId, subUnitId, rule) {
|
|
804
804
|
switch (rule.rule.type) {
|
|
805
|
-
case
|
|
806
|
-
if (rule.rule.subType ===
|
|
805
|
+
case "highlightCell":
|
|
806
|
+
if (rule.rule.subType === "formula") {
|
|
807
807
|
const formulaText = rule.rule.value;
|
|
808
808
|
if (formulaText) this.registerFormulaWithRange(unitId, subUnitId, rule.cfId, formulaText, rule.ranges);
|
|
809
809
|
}
|
|
@@ -946,13 +946,6 @@ ConditionalFormattingFormulaService = __decorate([__decorateParam(0, (0, _univer
|
|
|
946
946
|
|
|
947
947
|
//#endregion
|
|
948
948
|
//#region src/models/calculate-unit-v2/base-calculate-unit.ts
|
|
949
|
-
let CalculateEmitStatus = /* @__PURE__ */ function(CalculateEmitStatus) {
|
|
950
|
-
CalculateEmitStatus["preComputingStart"] = "preComputingStart";
|
|
951
|
-
CalculateEmitStatus["preComputing"] = "preComputing";
|
|
952
|
-
CalculateEmitStatus["preComputingEnd"] = "preComputingEnd";
|
|
953
|
-
CalculateEmitStatus["preComputingError"] = "preComputingError";
|
|
954
|
-
return CalculateEmitStatus;
|
|
955
|
-
}({});
|
|
956
949
|
/**
|
|
957
950
|
* Processing Main Path Calculation Logic
|
|
958
951
|
*/
|
|
@@ -960,7 +953,7 @@ var BaseCalculateUnit = class {
|
|
|
960
953
|
constructor(_context) {
|
|
961
954
|
this._context = _context;
|
|
962
955
|
_defineProperty(this, "_cache", void 0);
|
|
963
|
-
_defineProperty(this, "_preComputingStatus$", new rxjs.BehaviorSubject(
|
|
956
|
+
_defineProperty(this, "_preComputingStatus$", new rxjs.BehaviorSubject("preComputingStart"));
|
|
964
957
|
_defineProperty(this, "preComputingStatus$", this._preComputingStatus$.asObservable().pipe((0, rxjs_operators.distinctUntilChanged)()));
|
|
965
958
|
_defineProperty(this, "_preComputingCache", void 0);
|
|
966
959
|
_defineProperty(this, "_rule", void 0);
|
|
@@ -976,7 +969,7 @@ var BaseCalculateUnit = class {
|
|
|
976
969
|
this._cache.clear();
|
|
977
970
|
}
|
|
978
971
|
resetPreComputingCache() {
|
|
979
|
-
this._preComputingStatus$.next(
|
|
972
|
+
this._preComputingStatus$.next("preComputingStart");
|
|
980
973
|
this._preComputingCache = null;
|
|
981
974
|
}
|
|
982
975
|
updateRule(rule) {
|
|
@@ -985,15 +978,15 @@ var BaseCalculateUnit = class {
|
|
|
985
978
|
}
|
|
986
979
|
getCell(row, col) {
|
|
987
980
|
const key = this._createKey(row, col);
|
|
988
|
-
if (this._preComputingStatus$.getValue() ===
|
|
981
|
+
if (this._preComputingStatus$.getValue() === "preComputing") return this._cache.get(key);
|
|
989
982
|
let preComputingResult = this.getPreComputingResult(row, col);
|
|
990
983
|
if (preComputingResult === null) {
|
|
991
|
-
this._preComputingStatus$.next(
|
|
984
|
+
this._preComputingStatus$.next("preComputingStart");
|
|
992
985
|
this.preComputing(row, col, this._getContext());
|
|
993
986
|
preComputingResult = this.getPreComputingResult(row, col);
|
|
994
987
|
if (preComputingResult === null) return this._cache.get(key);
|
|
995
988
|
}
|
|
996
|
-
this._preComputingStatus$.next(
|
|
989
|
+
this._preComputingStatus$.next("preComputingEnd");
|
|
997
990
|
if (this._cache.has(key)) return this._cache.get(key);
|
|
998
991
|
const result = this.getCellResult(row, col, preComputingResult, this._getContext());
|
|
999
992
|
if (result !== null) this._setCache(row, col, result);
|
|
@@ -1020,7 +1013,7 @@ var BaseCalculateUnit = class {
|
|
|
1020
1013
|
}
|
|
1021
1014
|
_initClearCacheListener() {
|
|
1022
1015
|
this.preComputingStatus$.subscribe((e) => {
|
|
1023
|
-
if (e ===
|
|
1016
|
+
if (e === "preComputingEnd") this.clearCache();
|
|
1024
1017
|
});
|
|
1025
1018
|
}
|
|
1026
1019
|
};
|
|
@@ -1032,7 +1025,7 @@ var ColorScaleCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1032
1025
|
const rule = context.rule;
|
|
1033
1026
|
const worksheet = context.worksheet;
|
|
1034
1027
|
const matrix = new _univerjs_core.ObjectMatrix();
|
|
1035
|
-
if (!rule.rule.config.every((item) => item.value.type ===
|
|
1028
|
+
if (!rule.rule.config.every((item) => item.value.type === "num")) filterRange(rule.ranges, worksheet.getMaxRows() - 1, worksheet.getMaxColumns() - 1).forEach((range) => {
|
|
1036
1029
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
1037
1030
|
const cell = context.getCellValue(row, col);
|
|
1038
1031
|
const v = cell && cell.v;
|
|
@@ -1063,10 +1056,10 @@ var ColorScaleCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1063
1056
|
sortValue: _configList.map((item) => item.value.result).sort((a, b) => a - b)
|
|
1064
1057
|
}).result;
|
|
1065
1058
|
this.setPreComputingCache(colorList);
|
|
1066
|
-
this._preComputingStatus$.next(
|
|
1059
|
+
this._preComputingStatus$.next("preComputingEnd");
|
|
1067
1060
|
return;
|
|
1068
1061
|
}
|
|
1069
|
-
this._preComputingStatus$.next(
|
|
1062
|
+
this._preComputingStatus$.next("preComputing");
|
|
1070
1063
|
}
|
|
1071
1064
|
getCellResult(row, col, preComputingResult, context) {
|
|
1072
1065
|
if (!preComputingResult) return null;
|
|
@@ -1194,7 +1187,7 @@ var DataBarCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1194
1187
|
const ruleConfig = rule.rule;
|
|
1195
1188
|
const worksheet = context.worksheet;
|
|
1196
1189
|
const matrix = new _univerjs_core.ObjectMatrix();
|
|
1197
|
-
if (![rule.rule.config.max, rule.rule.config.min].every((e) => e.type ===
|
|
1190
|
+
if (![rule.rule.config.max, rule.rule.config.min].every((e) => e.type === "num")) filterRange(rule.ranges, worksheet.getMaxRows() - 1, worksheet.getMaxColumns() - 1).forEach((range) => {
|
|
1198
1191
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
1199
1192
|
const cell = context.getCellValue(row, col);
|
|
1200
1193
|
const v = cell && cell.v;
|
|
@@ -1218,7 +1211,7 @@ var DataBarCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1218
1211
|
const v = Number(_min.result);
|
|
1219
1212
|
min = Number.isNaN(v) ? 0 : v;
|
|
1220
1213
|
} else {
|
|
1221
|
-
this._preComputingStatus$.next(
|
|
1214
|
+
this._preComputingStatus$.next("preComputing");
|
|
1222
1215
|
return;
|
|
1223
1216
|
}
|
|
1224
1217
|
if (_max.status === _univerjs_engine_formula.FormulaResultStatus.SUCCESS) {
|
|
@@ -1237,10 +1230,10 @@ var DataBarCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1237
1230
|
max,
|
|
1238
1231
|
startPoint
|
|
1239
1232
|
});
|
|
1240
|
-
this._preComputingStatus$.next(
|
|
1233
|
+
this._preComputingStatus$.next("preComputingEnd");
|
|
1241
1234
|
return;
|
|
1242
1235
|
}
|
|
1243
|
-
this._preComputingStatus$.next(
|
|
1236
|
+
this._preComputingStatus$.next("preComputing");
|
|
1244
1237
|
}
|
|
1245
1238
|
getCellResult(row, col, preComputingResult, context) {
|
|
1246
1239
|
const { min, max, startPoint } = preComputingResult;
|
|
@@ -1317,7 +1310,7 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1317
1310
|
const ranges = filterRange(context.rule.ranges, context.worksheet.getMaxRows() - 1, context.worksheet.getMaxColumns() - 1);
|
|
1318
1311
|
const getCache = () => {
|
|
1319
1312
|
switch (ruleConfig.subType) {
|
|
1320
|
-
case
|
|
1313
|
+
case "average": {
|
|
1321
1314
|
let sum = 0;
|
|
1322
1315
|
let count = 0;
|
|
1323
1316
|
ranges.forEach((range) => {
|
|
@@ -1335,8 +1328,8 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1335
1328
|
type: ruleConfig.subType
|
|
1336
1329
|
};
|
|
1337
1330
|
}
|
|
1338
|
-
case
|
|
1339
|
-
case
|
|
1331
|
+
case "uniqueValues":
|
|
1332
|
+
case "duplicateValues": {
|
|
1340
1333
|
const cacheMap = /* @__PURE__ */ new Map();
|
|
1341
1334
|
ranges.forEach((range) => {
|
|
1342
1335
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
@@ -1353,7 +1346,7 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1353
1346
|
type: ruleConfig.subType
|
|
1354
1347
|
};
|
|
1355
1348
|
}
|
|
1356
|
-
case
|
|
1349
|
+
case "rank": {
|
|
1357
1350
|
let allValue = [];
|
|
1358
1351
|
ranges.forEach((range) => {
|
|
1359
1352
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
@@ -1384,86 +1377,86 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1384
1377
|
type: ruleConfig.subType
|
|
1385
1378
|
};
|
|
1386
1379
|
}
|
|
1387
|
-
case
|
|
1380
|
+
case "formula": {
|
|
1388
1381
|
const _ruleConfig = ruleConfig;
|
|
1389
1382
|
const conditionalFormattingFormulaService = context.accessor.get(ConditionalFormattingFormulaService);
|
|
1390
1383
|
const normalizedRanges = sortRangesByTopLeft(context.rule.ranges);
|
|
1391
1384
|
conditionalFormattingFormulaService.registerFormulaWithRange(context.unitId, context.subUnitId, context.rule.cfId, _ruleConfig.value, normalizedRanges);
|
|
1392
1385
|
const result = conditionalFormattingFormulaService.getFormulaMatrix(context.unitId, context.subUnitId, context.rule.cfId, _ruleConfig.value);
|
|
1393
1386
|
if (result && result.status === _univerjs_engine_formula.FormulaResultStatus.SUCCESS) {
|
|
1394
|
-
this._preComputingStatus$.next(
|
|
1387
|
+
this._preComputingStatus$.next("preComputingEnd");
|
|
1395
1388
|
return {
|
|
1396
1389
|
value: result.result,
|
|
1397
1390
|
type: ruleConfig.subType
|
|
1398
1391
|
};
|
|
1399
|
-
} else this._preComputingStatus$.next(
|
|
1392
|
+
} else this._preComputingStatus$.next("preComputing");
|
|
1400
1393
|
return null;
|
|
1401
1394
|
}
|
|
1402
|
-
case
|
|
1403
|
-
case
|
|
1395
|
+
case "timePeriod": switch (ruleConfig.operator) {
|
|
1396
|
+
case "last7Days": return {
|
|
1404
1397
|
value: {
|
|
1405
1398
|
start: (0, _univerjs_core.dateKit)().subtract(7, "day").valueOf(),
|
|
1406
1399
|
end: (0, _univerjs_core.dateKit)().valueOf()
|
|
1407
1400
|
},
|
|
1408
1401
|
type: ruleConfig.subType
|
|
1409
1402
|
};
|
|
1410
|
-
case
|
|
1403
|
+
case "lastMonth": return {
|
|
1411
1404
|
value: {
|
|
1412
1405
|
start: (0, _univerjs_core.dateKit)().startOf("month").subtract(1, "month").valueOf(),
|
|
1413
1406
|
end: (0, _univerjs_core.dateKit)().endOf("month").subtract(1, "month").valueOf()
|
|
1414
1407
|
},
|
|
1415
1408
|
type: ruleConfig.subType
|
|
1416
1409
|
};
|
|
1417
|
-
case
|
|
1410
|
+
case "lastWeek": return {
|
|
1418
1411
|
value: {
|
|
1419
1412
|
start: (0, _univerjs_core.dateKit)().startOf("week").subtract(1, "week").valueOf(),
|
|
1420
1413
|
end: (0, _univerjs_core.dateKit)().endOf("week").subtract(1, "week").valueOf()
|
|
1421
1414
|
},
|
|
1422
1415
|
type: ruleConfig.subType
|
|
1423
1416
|
};
|
|
1424
|
-
case
|
|
1417
|
+
case "nextMonth": return {
|
|
1425
1418
|
value: {
|
|
1426
1419
|
start: (0, _univerjs_core.dateKit)().startOf("month").add(1, "month").valueOf(),
|
|
1427
1420
|
end: (0, _univerjs_core.dateKit)().endOf("month").add(1, "month").valueOf()
|
|
1428
1421
|
},
|
|
1429
1422
|
type: ruleConfig.subType
|
|
1430
1423
|
};
|
|
1431
|
-
case
|
|
1424
|
+
case "nextWeek": return {
|
|
1432
1425
|
value: {
|
|
1433
1426
|
start: (0, _univerjs_core.dateKit)().startOf("week").add(1, "week").valueOf(),
|
|
1434
1427
|
end: (0, _univerjs_core.dateKit)().endOf("week").add(1, "week").valueOf()
|
|
1435
1428
|
},
|
|
1436
1429
|
type: ruleConfig.subType
|
|
1437
1430
|
};
|
|
1438
|
-
case
|
|
1431
|
+
case "thisMonth": return {
|
|
1439
1432
|
value: {
|
|
1440
1433
|
start: (0, _univerjs_core.dateKit)().startOf("month").valueOf(),
|
|
1441
1434
|
end: (0, _univerjs_core.dateKit)().endOf("month").valueOf()
|
|
1442
1435
|
},
|
|
1443
1436
|
type: ruleConfig.subType
|
|
1444
1437
|
};
|
|
1445
|
-
case
|
|
1438
|
+
case "thisWeek": return {
|
|
1446
1439
|
value: {
|
|
1447
1440
|
start: (0, _univerjs_core.dateKit)().startOf("week").valueOf(),
|
|
1448
1441
|
end: (0, _univerjs_core.dateKit)().endOf("week").valueOf()
|
|
1449
1442
|
},
|
|
1450
1443
|
type: ruleConfig.subType
|
|
1451
1444
|
};
|
|
1452
|
-
case
|
|
1445
|
+
case "today": return {
|
|
1453
1446
|
value: {
|
|
1454
1447
|
start: (0, _univerjs_core.dateKit)().startOf("day").valueOf(),
|
|
1455
1448
|
end: (0, _univerjs_core.dateKit)().endOf("day").valueOf()
|
|
1456
1449
|
},
|
|
1457
1450
|
type: ruleConfig.subType
|
|
1458
1451
|
};
|
|
1459
|
-
case
|
|
1452
|
+
case "tomorrow": return {
|
|
1460
1453
|
value: {
|
|
1461
1454
|
start: (0, _univerjs_core.dateKit)().startOf("day").add(1, "day").valueOf(),
|
|
1462
1455
|
end: (0, _univerjs_core.dateKit)().endOf("day").add(1, "day").valueOf()
|
|
1463
1456
|
},
|
|
1464
1457
|
type: ruleConfig.subType
|
|
1465
1458
|
};
|
|
1466
|
-
case
|
|
1459
|
+
case "yesterday": return {
|
|
1467
1460
|
value: {
|
|
1468
1461
|
start: (0, _univerjs_core.dateKit)().startOf("day").subtract(1, "day").valueOf(),
|
|
1469
1462
|
end: (0, _univerjs_core.dateKit)().endOf("day").subtract(1, "day").valueOf()
|
|
@@ -1481,12 +1474,12 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1481
1474
|
const ruleConfig = context.rule.rule;
|
|
1482
1475
|
const run = () => {
|
|
1483
1476
|
switch (ruleConfig.subType) {
|
|
1484
|
-
case
|
|
1477
|
+
case "number": {
|
|
1485
1478
|
const v = cellValue && Number(cellValue.v);
|
|
1486
1479
|
const isNumber = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === _univerjs_core.CellValueType.NUMBER;
|
|
1487
1480
|
const subRuleConfig = ruleConfig;
|
|
1488
1481
|
if (!isNumber) {
|
|
1489
|
-
if ([
|
|
1482
|
+
if (["notEqual", "notBetween"].includes(subRuleConfig.operator)) return true;
|
|
1490
1483
|
return false;
|
|
1491
1484
|
}
|
|
1492
1485
|
if (isNullable(v) || Number.isNaN(v)) return;
|
|
@@ -1495,54 +1488,54 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1495
1488
|
value: subRuleConfig.value || 0
|
|
1496
1489
|
}, v || 0);
|
|
1497
1490
|
}
|
|
1498
|
-
case
|
|
1491
|
+
case "text": {
|
|
1499
1492
|
const subRuleConfig = ruleConfig;
|
|
1500
1493
|
const value = getCellValue(cellValue);
|
|
1501
1494
|
const v = isNullable(value) ? "" : String(value);
|
|
1502
1495
|
const condition = subRuleConfig.value || "";
|
|
1503
1496
|
switch (subRuleConfig.operator) {
|
|
1504
|
-
case
|
|
1505
|
-
case
|
|
1506
|
-
case
|
|
1507
|
-
case
|
|
1508
|
-
case
|
|
1509
|
-
case
|
|
1510
|
-
case
|
|
1511
|
-
case
|
|
1512
|
-
case
|
|
1513
|
-
case
|
|
1497
|
+
case "beginsWith": return v.startsWith(condition);
|
|
1498
|
+
case "containsBlanks": return /^\s*$/.test(v);
|
|
1499
|
+
case "notContainsBlanks": return !/^\s*$/.test(v);
|
|
1500
|
+
case "containsErrors": return _univerjs_engine_formula.ERROR_TYPE_SET.has(v);
|
|
1501
|
+
case "notContainsErrors": return !_univerjs_engine_formula.ERROR_TYPE_SET.has(v);
|
|
1502
|
+
case "containsText": return v.indexOf(condition) > -1;
|
|
1503
|
+
case "notContainsText": return v.indexOf(condition) === -1;
|
|
1504
|
+
case "endsWith": return v.endsWith(condition);
|
|
1505
|
+
case "equal": return v === condition;
|
|
1506
|
+
case "notEqual": return v !== condition;
|
|
1514
1507
|
default: return false;
|
|
1515
1508
|
}
|
|
1516
1509
|
}
|
|
1517
|
-
case
|
|
1510
|
+
case "timePeriod": {
|
|
1518
1511
|
const value = getCellValue(cellValue);
|
|
1519
1512
|
if (isNullable(value) || Number.isNaN(Number(value)) || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== _univerjs_core.CellValueType.NUMBER || !preComputingResult) return;
|
|
1520
1513
|
const v = serialTimeToTimestamp(Number(value));
|
|
1521
1514
|
const { start, end } = preComputingResult.value;
|
|
1522
1515
|
return v >= start && v <= end;
|
|
1523
1516
|
}
|
|
1524
|
-
case
|
|
1517
|
+
case "average": {
|
|
1525
1518
|
const value = cellValue && cellValue.v;
|
|
1526
1519
|
const v = Number(value);
|
|
1527
1520
|
const isNumber = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === _univerjs_core.CellValueType.NUMBER;
|
|
1528
1521
|
const subRuleConfig = ruleConfig;
|
|
1529
1522
|
if (!isNumber) {
|
|
1530
|
-
if (
|
|
1523
|
+
if ("notEqual" === subRuleConfig.operator) return true;
|
|
1531
1524
|
return false;
|
|
1532
1525
|
}
|
|
1533
1526
|
if (isNullable(value) || Number.isNaN(v) || !preComputingResult) return false;
|
|
1534
1527
|
const average = preComputingResult.value;
|
|
1535
1528
|
switch (subRuleConfig.operator) {
|
|
1536
|
-
case
|
|
1537
|
-
case
|
|
1538
|
-
case
|
|
1539
|
-
case
|
|
1540
|
-
case
|
|
1541
|
-
case
|
|
1529
|
+
case "greaterThan": return v > average;
|
|
1530
|
+
case "greaterThanOrEqual": return v >= average;
|
|
1531
|
+
case "lessThan": return v < average;
|
|
1532
|
+
case "lessThanOrEqual": return v <= average;
|
|
1533
|
+
case "equal": return isFloatsEqual(v, average);
|
|
1534
|
+
case "notEqual": return !isFloatsEqual(v, average);
|
|
1542
1535
|
default: return false;
|
|
1543
1536
|
}
|
|
1544
1537
|
}
|
|
1545
|
-
case
|
|
1538
|
+
case "rank": {
|
|
1546
1539
|
const value = getCellValue(cellValue);
|
|
1547
1540
|
const v = Number(value);
|
|
1548
1541
|
if (isNullable(value) || Number.isNaN(v) || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== _univerjs_core.CellValueType.NUMBER || !preComputingResult) return false;
|
|
@@ -1550,18 +1543,18 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1550
1543
|
if (ruleConfig.isBottom) return v <= targetValue;
|
|
1551
1544
|
else return v >= targetValue;
|
|
1552
1545
|
}
|
|
1553
|
-
case
|
|
1546
|
+
case "uniqueValues": {
|
|
1554
1547
|
const value = getCellValue(cellValue);
|
|
1555
1548
|
if (isNullable(value) || !preComputingResult) return false;
|
|
1556
1549
|
return preComputingResult.value.get(value) === 1;
|
|
1557
1550
|
}
|
|
1558
|
-
case
|
|
1551
|
+
case "duplicateValues": {
|
|
1559
1552
|
const value = getCellValue(cellValue);
|
|
1560
1553
|
if (isNullable(value) || !preComputingResult) return false;
|
|
1561
1554
|
const uniqueCacheValue = preComputingResult.value.get(value);
|
|
1562
1555
|
return uniqueCacheValue && uniqueCacheValue !== 1;
|
|
1563
1556
|
}
|
|
1564
|
-
case
|
|
1557
|
+
case "formula": {
|
|
1565
1558
|
const _ruleConfig = ruleConfig;
|
|
1566
1559
|
const conditionalFormattingFormulaService = context.accessor.get(ConditionalFormattingFormulaService);
|
|
1567
1560
|
const firstRange = sortRangesByTopLeft(context.rule.ranges)[0];
|
|
@@ -1594,7 +1587,7 @@ var IconSetCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1594
1587
|
const ruleConfig = context.rule.rule;
|
|
1595
1588
|
const worksheet = context.worksheet;
|
|
1596
1589
|
const matrix = new _univerjs_core.ObjectMatrix();
|
|
1597
|
-
if (!ruleConfig.config.every((e) => e.value.type ===
|
|
1590
|
+
if (!ruleConfig.config.every((e) => e.value.type === "num")) filterRange(context.rule.ranges, worksheet.getMaxRows() - 1, worksheet.getMaxColumns() - 1).forEach((range) => {
|
|
1598
1591
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
1599
1592
|
const cell = context.getCellValue(row, col);
|
|
1600
1593
|
const v = cell && cell.v;
|
|
@@ -1630,10 +1623,10 @@ var IconSetCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1630
1623
|
return result;
|
|
1631
1624
|
}, []);
|
|
1632
1625
|
this.setPreComputingCache(splitValue);
|
|
1633
|
-
this._preComputingStatus$.next(
|
|
1626
|
+
this._preComputingStatus$.next("preComputingEnd");
|
|
1634
1627
|
return;
|
|
1635
1628
|
}
|
|
1636
|
-
this._preComputingStatus$.next(
|
|
1629
|
+
this._preComputingStatus$.next("preComputing");
|
|
1637
1630
|
}
|
|
1638
1631
|
getCellResult(row, col, preComputingResult, context) {
|
|
1639
1632
|
if (!preComputingResult) return null;
|
|
@@ -1788,7 +1781,7 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
|
|
|
1788
1781
|
if (e.type === "set") {
|
|
1789
1782
|
const { unitId, subUnitId } = e;
|
|
1790
1783
|
const oldRule = e.oldRule;
|
|
1791
|
-
if (oldRule.rule.type ===
|
|
1784
|
+
if (oldRule.rule.type === "highlightCell" && oldRule.rule.subType === "formula") this._conditionalFormattingFormulaService.deleteCache(unitId, subUnitId, oldRule.cfId);
|
|
1792
1785
|
}
|
|
1793
1786
|
}));
|
|
1794
1787
|
}
|
|
@@ -1876,10 +1869,10 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
|
|
|
1876
1869
|
getCellValue: (row, col) => worksheet.getCellRaw(row, col) || {}
|
|
1877
1870
|
};
|
|
1878
1871
|
switch (rule.rule.type) {
|
|
1879
|
-
case
|
|
1880
|
-
case
|
|
1881
|
-
case
|
|
1882
|
-
case
|
|
1872
|
+
case "colorScale": return new ColorScaleCalculateUnit(context);
|
|
1873
|
+
case "dataBar": return new DataBarCalculateUnit(context);
|
|
1874
|
+
case "highlightCell": return new HighlightCellCalculateUnit(context);
|
|
1875
|
+
case "iconSet": return new IconSetCalculateUnit(context);
|
|
1883
1876
|
}
|
|
1884
1877
|
}
|
|
1885
1878
|
_createCacheKey(unitId, subUnitId, row, col) {
|
|
@@ -1969,7 +1962,7 @@ const serialTimeToTimestamp = (value) => {
|
|
|
1969
1962
|
};
|
|
1970
1963
|
const getValueByType = (value, matrix, context) => {
|
|
1971
1964
|
switch (value.type) {
|
|
1972
|
-
case
|
|
1965
|
+
case "max": {
|
|
1973
1966
|
let max = 0;
|
|
1974
1967
|
matrix.forValue((row, col, value) => {
|
|
1975
1968
|
if (value > max) max = value;
|
|
@@ -1979,7 +1972,7 @@ const getValueByType = (value, matrix, context) => {
|
|
|
1979
1972
|
result: max
|
|
1980
1973
|
};
|
|
1981
1974
|
}
|
|
1982
|
-
case
|
|
1975
|
+
case "min": {
|
|
1983
1976
|
let min;
|
|
1984
1977
|
matrix.forValue((row, col, value) => {
|
|
1985
1978
|
if (min === void 0) min = value;
|
|
@@ -1990,7 +1983,7 @@ const getValueByType = (value, matrix, context) => {
|
|
|
1990
1983
|
result: min
|
|
1991
1984
|
};
|
|
1992
1985
|
}
|
|
1993
|
-
case
|
|
1986
|
+
case "percent": {
|
|
1994
1987
|
let max;
|
|
1995
1988
|
let min;
|
|
1996
1989
|
matrix.forValue((row, col, value) => {
|
|
@@ -2008,7 +2001,7 @@ const getValueByType = (value, matrix, context) => {
|
|
|
2008
2001
|
result: length * (v / 100) + (min || 0)
|
|
2009
2002
|
};
|
|
2010
2003
|
}
|
|
2011
|
-
case
|
|
2004
|
+
case "percentile": {
|
|
2012
2005
|
const list = matrix.toNativeArray().sort((a, b) => a - b);
|
|
2013
2006
|
const v = Math.max(Math.min(Number(value.value) || 0, 100), 0);
|
|
2014
2007
|
const index = (list.length - 1) * v / 100;
|
|
@@ -2020,14 +2013,14 @@ const getValueByType = (value, matrix, context) => {
|
|
|
2020
2013
|
result
|
|
2021
2014
|
};
|
|
2022
2015
|
}
|
|
2023
|
-
case
|
|
2016
|
+
case "formula": {
|
|
2024
2017
|
const { accessor, unitId, subUnitId, cfId } = context;
|
|
2025
2018
|
const formulaText = String(value.value);
|
|
2026
2019
|
const conditionalFormattingFormulaService = accessor.get(ConditionalFormattingFormulaService);
|
|
2027
2020
|
conditionalFormattingFormulaService.registerFormulaWithRange(unitId, subUnitId, cfId, formulaText);
|
|
2028
2021
|
return conditionalFormattingFormulaService.getFormulaResultWithCoords(unitId, subUnitId, cfId, formulaText);
|
|
2029
2022
|
}
|
|
2030
|
-
case
|
|
2023
|
+
case "num":
|
|
2031
2024
|
default: {
|
|
2032
2025
|
const v = Number(value.value);
|
|
2033
2026
|
return {
|
|
@@ -2054,33 +2047,33 @@ const getCacheStyleMatrix = (unitId, subUnitId, rule, context) => {
|
|
|
2054
2047
|
};
|
|
2055
2048
|
const compareWithNumber = (config, v) => {
|
|
2056
2049
|
switch (config.operator) {
|
|
2057
|
-
case
|
|
2050
|
+
case "between": {
|
|
2058
2051
|
if (typeof config.value !== "object" || !config.value.length) return;
|
|
2059
2052
|
const start = Math.min(...config.value);
|
|
2060
2053
|
const end = Math.max(...config.value);
|
|
2061
2054
|
return v >= start && v <= end;
|
|
2062
2055
|
}
|
|
2063
|
-
case
|
|
2056
|
+
case "notBetween": {
|
|
2064
2057
|
if (typeof config.value !== "object" || !config.value.length) return;
|
|
2065
2058
|
const start = Math.min(...config.value);
|
|
2066
2059
|
const end = Math.max(...config.value);
|
|
2067
2060
|
return !(v >= start && v <= end);
|
|
2068
2061
|
}
|
|
2069
|
-
case
|
|
2070
|
-
case
|
|
2071
|
-
case
|
|
2072
|
-
case
|
|
2073
|
-
case
|
|
2074
|
-
case
|
|
2062
|
+
case "equal": return isFloatsEqual(config.value || 0, v);
|
|
2063
|
+
case "notEqual": return !isFloatsEqual(config.value || 0, v);
|
|
2064
|
+
case "greaterThan": return v > (config.value || 0);
|
|
2065
|
+
case "greaterThanOrEqual": return v >= (config.value || 0);
|
|
2066
|
+
case "lessThan": return v < (config.value || 0);
|
|
2067
|
+
case "lessThanOrEqual": return v <= (config.value || 0);
|
|
2075
2068
|
default: return false;
|
|
2076
2069
|
}
|
|
2077
2070
|
};
|
|
2078
2071
|
const getOppositeOperator = (operator) => {
|
|
2079
2072
|
switch (operator) {
|
|
2080
|
-
case
|
|
2081
|
-
case
|
|
2082
|
-
case
|
|
2083
|
-
case
|
|
2073
|
+
case "greaterThan": return "lessThanOrEqual";
|
|
2074
|
+
case "greaterThanOrEqual": return "lessThan";
|
|
2075
|
+
case "lessThan": return "greaterThanOrEqual";
|
|
2076
|
+
case "lessThanOrEqual": return "greaterThan";
|
|
2084
2077
|
}
|
|
2085
2078
|
return operator;
|
|
2086
2079
|
};
|
|
@@ -2453,7 +2446,7 @@ const EMPTY_ICON_TYPE = "EMPTY_ICON_TYPE";
|
|
|
2453
2446
|
//#endregion
|
|
2454
2447
|
//#region package.json
|
|
2455
2448
|
var name = "@univerjs/sheets-conditional-formatting";
|
|
2456
|
-
var version = "0.
|
|
2449
|
+
var version = "0.22.0";
|
|
2457
2450
|
|
|
2458
2451
|
//#endregion
|
|
2459
2452
|
//#region src/config/config.ts
|
|
@@ -2484,18 +2477,18 @@ let ConditionalFormattingService = class ConditionalFormattingService extends _u
|
|
|
2484
2477
|
}
|
|
2485
2478
|
_mergeComposeResult(result, rule, ruleResult) {
|
|
2486
2479
|
const type = rule.rule.type;
|
|
2487
|
-
if (type ===
|
|
2480
|
+
if (type === "highlightCell") {
|
|
2488
2481
|
ruleResult && (0, _univerjs_core.merge)(result, { style: ruleResult });
|
|
2489
2482
|
return;
|
|
2490
2483
|
}
|
|
2491
|
-
if (type ===
|
|
2484
|
+
if (type === "colorScale") {
|
|
2492
2485
|
if (ruleResult && typeof ruleResult === "string") result.style = {
|
|
2493
2486
|
...result.style || {},
|
|
2494
2487
|
bg: { rgb: ruleResult }
|
|
2495
2488
|
};
|
|
2496
2489
|
return;
|
|
2497
2490
|
}
|
|
2498
|
-
if (type ===
|
|
2491
|
+
if (type === "dataBar") {
|
|
2499
2492
|
const ruleCache = ruleResult;
|
|
2500
2493
|
if (ruleCache) {
|
|
2501
2494
|
result.dataBar = ruleCache;
|
|
@@ -2503,7 +2496,7 @@ let ConditionalFormattingService = class ConditionalFormattingService extends _u
|
|
|
2503
2496
|
}
|
|
2504
2497
|
return;
|
|
2505
2498
|
}
|
|
2506
|
-
if (type ===
|
|
2499
|
+
if (type === "iconSet") {
|
|
2507
2500
|
const ruleCache = ruleResult;
|
|
2508
2501
|
if (ruleCache) {
|
|
2509
2502
|
result.iconSet = ruleCache;
|
|
@@ -2547,7 +2540,7 @@ let ConditionalFormattingService = class ConditionalFormattingService extends _u
|
|
|
2547
2540
|
return result;
|
|
2548
2541
|
}
|
|
2549
2542
|
_isRuleMatched(rule, ruleResult) {
|
|
2550
|
-
if (rule.rule.type ===
|
|
2543
|
+
if (rule.rule.type === "highlightCell") return !!ruleResult && typeof ruleResult === "object" && Object.keys(ruleResult).length > 0;
|
|
2551
2544
|
return !!ruleResult;
|
|
2552
2545
|
}
|
|
2553
2546
|
_initSnapshot() {
|