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