@univerjs/sheets-conditional-formatting 1.0.0-insiders.20260813-7c9aa50 → 1.0.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/LICENSE +176 -0
- package/README.md +10 -2
- package/lib/cjs/facade.js +18 -14
- package/lib/cjs/index.js +155 -114
- package/lib/cjs/locale/ar-SA.js +0 -1
- package/lib/cjs/locale/ca-ES.js +0 -1
- package/lib/cjs/locale/de-DE.js +0 -1
- package/lib/cjs/locale/en-US.js +0 -1
- package/lib/cjs/locale/es-ES.js +0 -1
- package/lib/cjs/locale/fa-IR.js +0 -1
- package/lib/cjs/locale/fr-FR.js +0 -1
- package/lib/cjs/locale/id-ID.js +0 -1
- package/lib/cjs/locale/it-IT.js +0 -1
- package/lib/cjs/locale/ja-JP.js +0 -1
- package/lib/cjs/locale/ko-KR.js +0 -1
- package/lib/cjs/locale/pl-PL.js +0 -1
- package/lib/cjs/locale/pt-BR.js +0 -1
- package/lib/cjs/locale/ru-RU.js +0 -1
- package/lib/cjs/locale/sk-SK.js +0 -1
- package/lib/cjs/locale/vi-VN.js +0 -1
- package/lib/cjs/locale/zh-CN.js +0 -1
- package/lib/cjs/locale/zh-HK.js +0 -1
- package/lib/cjs/locale/zh-TW.js +0 -1
- package/lib/es/facade.js +18 -14
- package/lib/es/index.js +157 -115
- package/lib/facade.js +18 -14
- package/lib/index.js +157 -115
- package/lib/types/models/calculate-unit-v2/__test__/test.util.d.ts +38 -0
- package/lib/types/models/calculate-unit-v2/utils.d.ts +2 -3
- package/lib/types/models/conditional-formatting-view-model.d.ts +2 -0
- package/lib/types/render/data-bar.render.d.ts +4 -0
- package/lib/types/render/icon.render.d.ts +4 -0
- package/lib/types/render/type.d.ts +2 -1
- package/lib/types/services/conditional-formatting-formula.service.d.ts +3 -2
- package/lib/types/services/conditional-formatting-style-composer.service.d.ts +11 -6
- package/lib/types/utils/is-ranges-equal.d.ts +16 -0
- package/lib/types/utils/range.d.ts +18 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -145,9 +145,7 @@ const moveByAnchor = (start, end, ruleList, get) => {
|
|
|
145
145
|
ruleList.splice(endIndex + 1, 0, rule);
|
|
146
146
|
break;
|
|
147
147
|
case "self":
|
|
148
|
-
case "after":
|
|
149
|
-
ruleList.splice(endIndex, 0, rule);
|
|
150
|
-
break;
|
|
148
|
+
case "after": ruleList.splice(endIndex, 0, rule);
|
|
151
149
|
}
|
|
152
150
|
};
|
|
153
151
|
/**
|
|
@@ -221,7 +219,7 @@ const isAnchorEqual = (anchor1, anchor2) => {
|
|
|
221
219
|
const createCfId = () => `${(0, _univerjs_core.generateRandomId)(8)}`;
|
|
222
220
|
|
|
223
221
|
//#endregion
|
|
224
|
-
//#region \0@oxc-project+runtime@0.
|
|
222
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
225
223
|
function _typeof(o) {
|
|
226
224
|
"@babel/helpers - typeof";
|
|
227
225
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -232,7 +230,7 @@ function _typeof(o) {
|
|
|
232
230
|
}
|
|
233
231
|
|
|
234
232
|
//#endregion
|
|
235
|
-
//#region \0@oxc-project+runtime@0.
|
|
233
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
236
234
|
function toPrimitive(t, r) {
|
|
237
235
|
if ("object" != _typeof(t) || !t) return t;
|
|
238
236
|
var e = t[Symbol.toPrimitive];
|
|
@@ -245,14 +243,14 @@ function toPrimitive(t, r) {
|
|
|
245
243
|
}
|
|
246
244
|
|
|
247
245
|
//#endregion
|
|
248
|
-
//#region \0@oxc-project+runtime@0.
|
|
246
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
249
247
|
function toPropertyKey(t) {
|
|
250
248
|
var i = toPrimitive(t, "string");
|
|
251
249
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
252
250
|
}
|
|
253
251
|
|
|
254
252
|
//#endregion
|
|
255
|
-
//#region \0@oxc-project+runtime@0.
|
|
253
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
256
254
|
function _defineProperty(e, r, t) {
|
|
257
255
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
258
256
|
value: t,
|
|
@@ -486,7 +484,8 @@ const AddCfCommand = {
|
|
|
486
484
|
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
487
485
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
488
486
|
const conditionalFormattingRuleModel = accessor.get(ConditionalFormattingRuleModel);
|
|
489
|
-
const
|
|
487
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
488
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, params);
|
|
490
489
|
if (!target) return false;
|
|
491
490
|
const { unitId, subUnitId } = target;
|
|
492
491
|
const cfId = conditionalFormattingRuleModel.createCfId(unitId, subUnitId);
|
|
@@ -513,7 +512,7 @@ const AddCfCommand = {
|
|
|
513
512
|
};
|
|
514
513
|
|
|
515
514
|
//#endregion
|
|
516
|
-
//#region \0@oxc-project+runtime@0.
|
|
515
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
517
516
|
function __decorateParam(paramIndex, decorator) {
|
|
518
517
|
return function(target, key) {
|
|
519
518
|
decorator(target, key, paramIndex);
|
|
@@ -521,7 +520,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
521
520
|
}
|
|
522
521
|
|
|
523
522
|
//#endregion
|
|
524
|
-
//#region \0@oxc-project+runtime@0.
|
|
523
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
525
524
|
function __decorate(decorators, target, key, desc) {
|
|
526
525
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
527
526
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -792,7 +791,8 @@ const DeleteCfCommand = {
|
|
|
792
791
|
if (!params) return false;
|
|
793
792
|
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
794
793
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
795
|
-
const
|
|
794
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
795
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, params);
|
|
796
796
|
if (!target) return false;
|
|
797
797
|
const { unitId, subUnitId } = target;
|
|
798
798
|
const config = {
|
|
@@ -860,7 +860,8 @@ const SetCfCommand = {
|
|
|
860
860
|
if (!params) return false;
|
|
861
861
|
const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
|
|
862
862
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
863
|
-
const
|
|
863
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
864
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, params);
|
|
864
865
|
if (!target) return false;
|
|
865
866
|
const { unitId, subUnitId } = target;
|
|
866
867
|
const config = {
|
|
@@ -883,13 +884,43 @@ const SetCfCommand = {
|
|
|
883
884
|
}
|
|
884
885
|
};
|
|
885
886
|
|
|
887
|
+
//#endregion
|
|
888
|
+
//#region src/utils/range.ts
|
|
889
|
+
function getRangeInWorksheet(range, worksheet) {
|
|
890
|
+
const maxRows = worksheet.getMaxRows();
|
|
891
|
+
const maxColumns = worksheet.getMaxColumns();
|
|
892
|
+
if (maxRows <= 0 || maxColumns <= 0) return null;
|
|
893
|
+
const effectiveRange = (0, _univerjs_core.getIntersectRange)(_univerjs_core.Range.transformRange(range, worksheet), {
|
|
894
|
+
startRow: 0,
|
|
895
|
+
endRow: maxRows - 1,
|
|
896
|
+
startColumn: 0,
|
|
897
|
+
endColumn: maxColumns - 1
|
|
898
|
+
});
|
|
899
|
+
if (!effectiveRange) return null;
|
|
900
|
+
return {
|
|
901
|
+
startRow: effectiveRange.startRow,
|
|
902
|
+
endRow: effectiveRange.endRow,
|
|
903
|
+
startColumn: effectiveRange.startColumn,
|
|
904
|
+
endColumn: effectiveRange.endColumn
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
function getRangesInWorksheet(ranges, worksheet) {
|
|
908
|
+
const effectiveRanges = [];
|
|
909
|
+
ranges.forEach((range) => {
|
|
910
|
+
const effectiveRange = getRangeInWorksheet(range, worksheet);
|
|
911
|
+
if (effectiveRange) effectiveRanges.push(effectiveRange);
|
|
912
|
+
});
|
|
913
|
+
return effectiveRanges;
|
|
914
|
+
}
|
|
915
|
+
|
|
886
916
|
//#endregion
|
|
887
917
|
//#region src/services/conditional-formatting-formula.service.ts
|
|
888
918
|
let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaService extends _univerjs_core.Disposable {
|
|
889
|
-
constructor(_registerOtherFormulaService, _conditionalFormattingRuleModel) {
|
|
919
|
+
constructor(_registerOtherFormulaService, _conditionalFormattingRuleModel, _univerInstanceService) {
|
|
890
920
|
super();
|
|
891
921
|
this._registerOtherFormulaService = _registerOtherFormulaService;
|
|
892
922
|
this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel;
|
|
923
|
+
this._univerInstanceService = _univerInstanceService;
|
|
893
924
|
_defineProperty(this, "_formulaMap", /* @__PURE__ */ new Map());
|
|
894
925
|
_defineProperty(this, "_result$", new rxjs.Subject());
|
|
895
926
|
_defineProperty(this, "result$", this._result$.asObservable());
|
|
@@ -918,12 +949,10 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
|
|
|
918
949
|
*/
|
|
919
950
|
_registerRuleFormulas(unitId, subUnitId, rule) {
|
|
920
951
|
switch (rule.rule.type) {
|
|
921
|
-
case "highlightCell":
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
}
|
|
926
|
-
break;
|
|
952
|
+
case "highlightCell": if (rule.rule.subType === "formula") {
|
|
953
|
+
const formulaText = rule.rule.value;
|
|
954
|
+
if (formulaText) this.registerFormulaWithRange(unitId, subUnitId, rule.cfId, formulaText, rule.ranges);
|
|
955
|
+
}
|
|
927
956
|
}
|
|
928
957
|
}
|
|
929
958
|
_initFormulaResultChange() {
|
|
@@ -968,10 +997,15 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
|
|
|
968
997
|
startColumn: 0,
|
|
969
998
|
endColumn: 0
|
|
970
999
|
}]) {
|
|
1000
|
+
var _this$_univerInstance;
|
|
971
1001
|
const formulaMap = this._ensureSubunitFormulaMap(unitId, subUnitId);
|
|
972
1002
|
const cfFormulaId = this.createCFormulaId(cfId, formulaText);
|
|
973
1003
|
if (formulaMap.getValue(cfFormulaId, ["id"])) return;
|
|
974
|
-
const
|
|
1004
|
+
const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
1005
|
+
if (!worksheet) return;
|
|
1006
|
+
const effectiveRanges = getRangesInWorksheet(ranges, worksheet);
|
|
1007
|
+
if (!effectiveRanges.length) return;
|
|
1008
|
+
const sortedRanges = effectiveRanges.sort((a, b) => a.startRow !== b.startRow ? a.startRow - b.startRow : a.startColumn - b.startColumn);
|
|
975
1009
|
const formulaId = this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaText, sortedRanges, void 0, _univerjs_engine_formula.OtherFormulaBizType.CONDITIONAL_FORMATTING, cfId);
|
|
976
1010
|
formulaMap.addValue({
|
|
977
1011
|
formulaText,
|
|
@@ -1058,7 +1092,11 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
|
|
|
1058
1092
|
return `${cfId}_${formulaText}`;
|
|
1059
1093
|
}
|
|
1060
1094
|
};
|
|
1061
|
-
ConditionalFormattingFormulaService = __decorate([
|
|
1095
|
+
ConditionalFormattingFormulaService = __decorate([
|
|
1096
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_engine_formula.RegisterOtherFormulaService)),
|
|
1097
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(ConditionalFormattingRuleModel)),
|
|
1098
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService)
|
|
1099
|
+
], ConditionalFormattingFormulaService);
|
|
1062
1100
|
|
|
1063
1101
|
//#endregion
|
|
1064
1102
|
//#region src/models/calculate-unit-v2/base-calculate-unit.ts
|
|
@@ -1203,15 +1241,21 @@ var DataBar = class extends _univerjs_engine_render.SheetExtension {
|
|
|
1203
1241
|
super(..._args);
|
|
1204
1242
|
_defineProperty(this, "_paddingRightAndLeft", 2);
|
|
1205
1243
|
_defineProperty(this, "_paddingTopAndBottom", 2);
|
|
1244
|
+
_defineProperty(this, "_renderRangeResolver", null);
|
|
1206
1245
|
_defineProperty(this, "uKey", dataBarUKey);
|
|
1207
1246
|
_defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX$1);
|
|
1208
1247
|
_defineProperty(this, "_radius", 1);
|
|
1209
1248
|
}
|
|
1249
|
+
setRenderRangeResolver(resolver) {
|
|
1250
|
+
this._renderRangeResolver = resolver;
|
|
1251
|
+
}
|
|
1210
1252
|
draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
|
|
1211
1253
|
const { worksheet } = spreadsheetSkeleton;
|
|
1212
1254
|
if (!worksheet) return false;
|
|
1213
1255
|
const mergeCellRendered = /* @__PURE__ */ new Set();
|
|
1214
|
-
const
|
|
1256
|
+
const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
|
|
1257
|
+
const renderRanges = this._renderRangeResolver && worksheet.getMergeData().length === 0 ? this._renderRangeResolver(worksheet.getUnitId(), worksheet.getSheetId(), sourceRanges) ?? sourceRanges : sourceRanges;
|
|
1258
|
+
if (!renderRanges.length) return;
|
|
1215
1259
|
ctx.save();
|
|
1216
1260
|
renderRanges.forEach((range) => {
|
|
1217
1261
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
@@ -1266,6 +1310,10 @@ var DataBar = class extends _univerjs_engine_render.SheetExtension {
|
|
|
1266
1310
|
});
|
|
1267
1311
|
ctx.restore();
|
|
1268
1312
|
}
|
|
1313
|
+
dispose() {
|
|
1314
|
+
this._renderRangeResolver = null;
|
|
1315
|
+
super.dispose();
|
|
1316
|
+
}
|
|
1269
1317
|
_drawRectWithRoundedCorner(ctx, x, y, width, height, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius) {
|
|
1270
1318
|
const radius = this._radius;
|
|
1271
1319
|
if (!height || !width) return;
|
|
@@ -1379,28 +1427,29 @@ var DataBarCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1379
1427
|
isGradient,
|
|
1380
1428
|
isShowValue
|
|
1381
1429
|
};
|
|
1382
|
-
} else if (min < 0 && max > 0)
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1430
|
+
} else if (min < 0 && max > 0) {
|
|
1431
|
+
if (value > 0) {
|
|
1432
|
+
const v = getSafeValue(Math.min(value / max, 1) * 100);
|
|
1433
|
+
if (v === 0) return;
|
|
1434
|
+
return {
|
|
1435
|
+
color: ruleConfig.config.positiveColor || "#ffbe38",
|
|
1436
|
+
startPoint,
|
|
1437
|
+
value: v,
|
|
1438
|
+
isGradient,
|
|
1439
|
+
isShowValue
|
|
1440
|
+
};
|
|
1441
|
+
} else {
|
|
1442
|
+
const v = getSafeValue(Math.min(Math.abs(value) / Math.abs(min), 1) * 100);
|
|
1443
|
+
if (v === 0) return;
|
|
1444
|
+
return {
|
|
1445
|
+
color: ruleConfig.config.nativeColor || "#abd91a",
|
|
1446
|
+
startPoint,
|
|
1447
|
+
value: -v,
|
|
1448
|
+
isGradient,
|
|
1449
|
+
isShowValue
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
} else if (min >= 0 && max > 0) {
|
|
1404
1453
|
const length = max - min;
|
|
1405
1454
|
const startPoint = 0;
|
|
1406
1455
|
const v = getSafeValue((1 - (max - value) / length) * 100);
|
|
@@ -1452,7 +1501,8 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1452
1501
|
const cacheMap = /* @__PURE__ */ new Map();
|
|
1453
1502
|
ranges.forEach((range) => {
|
|
1454
1503
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
1455
|
-
const
|
|
1504
|
+
const cell = context.getCellValue(row, col);
|
|
1505
|
+
const v = getCellValue(cell);
|
|
1456
1506
|
if (!isNullable(v)) {
|
|
1457
1507
|
const cache = cacheMap.get(v);
|
|
1458
1508
|
if (cache) cacheMap.set(v, cache + 1);
|
|
@@ -1594,18 +1644,19 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1594
1644
|
const run = () => {
|
|
1595
1645
|
switch (ruleConfig.subType) {
|
|
1596
1646
|
case "number": {
|
|
1597
|
-
const v = cellValue && Number(cellValue.v);
|
|
1598
|
-
const isNumber = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === _univerjs_core.CellValueType.NUMBER;
|
|
1599
1647
|
const subRuleConfig = ruleConfig;
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1648
|
+
const value = cellValue === null || cellValue === void 0 ? void 0 : cellValue.v;
|
|
1649
|
+
if ((cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== _univerjs_core.CellValueType.FORCE_STRING && _univerjs_engine_formula.ERROR_TYPE_SET.has(value)) return false;
|
|
1650
|
+
if (value != null && ((cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === _univerjs_core.CellValueType.BOOLEAN || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== _univerjs_core.CellValueType.NUMBER && typeof value !== "number")) return [
|
|
1651
|
+
"notEqual",
|
|
1652
|
+
"notBetween",
|
|
1653
|
+
"greaterThan",
|
|
1654
|
+
"greaterThanOrEqual"
|
|
1655
|
+
].includes(subRuleConfig.operator);
|
|
1605
1656
|
return compareWithNumber({
|
|
1606
1657
|
operator: subRuleConfig.operator,
|
|
1607
|
-
value: subRuleConfig.value
|
|
1608
|
-
},
|
|
1658
|
+
value: subRuleConfig.value ?? 0
|
|
1659
|
+
}, Number(value ?? 0));
|
|
1609
1660
|
}
|
|
1610
1661
|
case "text": {
|
|
1611
1662
|
const subRuleConfig = ruleConfig;
|
|
@@ -1629,7 +1680,7 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1629
1680
|
case "timePeriod": {
|
|
1630
1681
|
const value = getCellValue(cellValue);
|
|
1631
1682
|
if (isNullable(value) || Number.isNaN(Number(value)) || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== _univerjs_core.CellValueType.NUMBER || !preComputingResult) return;
|
|
1632
|
-
const v = serialTimeToTimestamp(Number(value));
|
|
1683
|
+
const v = serialTimeToTimestamp(Number(value), context.workbook.getDateSystem());
|
|
1633
1684
|
const { start, end } = preComputingResult.value;
|
|
1634
1685
|
return v >= start && v <= end;
|
|
1635
1686
|
}
|
|
@@ -1788,7 +1839,7 @@ var IconSetCalculateUnit = class extends BaseCalculateUnit {
|
|
|
1788
1839
|
|
|
1789
1840
|
//#endregion
|
|
1790
1841
|
//#region src/models/conditional-formatting-view-model.ts
|
|
1791
|
-
const CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH =
|
|
1842
|
+
const CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH = 9e3;
|
|
1792
1843
|
let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extends _univerjs_core.Disposable {
|
|
1793
1844
|
constructor(_injector, _conditionalFormattingRuleModel, _conditionalFormattingRangeIndexModel, _conditionalFormattingFormulaService, _univerInstanceService) {
|
|
1794
1845
|
super();
|
|
@@ -1800,7 +1851,9 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
|
|
|
1800
1851
|
_defineProperty(this, "_calculateUnitManagers", /* @__PURE__ */ new Map());
|
|
1801
1852
|
_defineProperty(this, "_cellCache", new _univerjs_core.LRUMap(CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH));
|
|
1802
1853
|
_defineProperty(this, "_markDirty$", new rxjs.Subject());
|
|
1854
|
+
_defineProperty(this, "_cacheClear$", new rxjs.Subject());
|
|
1803
1855
|
_defineProperty(this, "markDirty$", this._markDirty$.asObservable());
|
|
1856
|
+
_defineProperty(this, "cacheClear$", this._cacheClear$.asObservable());
|
|
1804
1857
|
_defineProperty(this, "_markRuleDirtyAtOnce", (unitId, subUnitId, cfId, isNeedResetPreComputingCache = true) => {
|
|
1805
1858
|
this._cellCache.clear();
|
|
1806
1859
|
if (isNeedResetPreComputingCache) {
|
|
@@ -1886,6 +1939,7 @@ let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extend
|
|
|
1886
1939
|
clearCache() {
|
|
1887
1940
|
this._calculateUnitManagers.clear();
|
|
1888
1941
|
this._cellCache.clear();
|
|
1942
|
+
this._cacheClear$.next();
|
|
1889
1943
|
}
|
|
1890
1944
|
_handleCustomFormulasSeparately() {
|
|
1891
1945
|
this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.subscribe((e) => {
|
|
@@ -1999,54 +2053,10 @@ const getCellValue = (cell) => {
|
|
|
1999
2053
|
const dataStream = (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream.replace(/\r\n$/, "");
|
|
2000
2054
|
return !isNullable(v) ? v : !isNullable(dataStream) ? dataStream : null;
|
|
2001
2055
|
};
|
|
2002
|
-
const
|
|
2003
|
-
|
|
2004
|
-
if (
|
|
2005
|
-
|
|
2006
|
-
1900,
|
|
2007
|
-
1,
|
|
2008
|
-
0
|
|
2009
|
-
];
|
|
2010
|
-
if (ord === 60) return [
|
|
2011
|
-
1900,
|
|
2012
|
-
2,
|
|
2013
|
-
29
|
|
2014
|
-
];
|
|
2015
|
-
if (ord < 60) return [
|
|
2016
|
-
1900,
|
|
2017
|
-
ord < 32 ? 1 : 2,
|
|
2018
|
-
(ord - 1) % 31 + 1
|
|
2019
|
-
];
|
|
2020
|
-
}
|
|
2021
|
-
let l = ord + 68569 + 2415019;
|
|
2022
|
-
const n = Math.floor(4 * l / 146097);
|
|
2023
|
-
l = l - Math.floor((146097 * n + 3) / 4);
|
|
2024
|
-
const i = Math.floor(4e3 * (l + 1) / 1461001);
|
|
2025
|
-
l = l - Math.floor(1461 * i / 4) + 31;
|
|
2026
|
-
const j = Math.floor(80 * l / 2447);
|
|
2027
|
-
const nDay = l - Math.floor(2447 * j / 80);
|
|
2028
|
-
l = Math.floor(j / 11);
|
|
2029
|
-
const nMonth = j + 2 - 12 * l;
|
|
2030
|
-
return [
|
|
2031
|
-
100 * (n - 49) + i + l | 0,
|
|
2032
|
-
nMonth | 0,
|
|
2033
|
-
nDay | 0
|
|
2034
|
-
];
|
|
2035
|
-
}
|
|
2036
|
-
const serialTimeToTimestamp = (value) => {
|
|
2037
|
-
let date = value | 0;
|
|
2038
|
-
const t = DAY_SIZE * (value - date);
|
|
2039
|
-
let time = Math.floor(t);
|
|
2040
|
-
if (t - time > .9999) {
|
|
2041
|
-
time += 1;
|
|
2042
|
-
if (time === DAY_SIZE) {
|
|
2043
|
-
time = 0;
|
|
2044
|
-
date += 1;
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
const x = time < 0 ? DAY_SIZE + time : time;
|
|
2048
|
-
const [y, m, d] = toYMD_1900(value, true);
|
|
2049
|
-
return (0, _univerjs_core.dateKit)(`${y}/${m}/${d} ${Math.floor(x / 60 / 60) % 60}:${Math.floor(x / 60) % 60}:${Math.floor(x) % 60}`).valueOf();
|
|
2056
|
+
const serialTimeToTimestamp = (value, dateSystem = _univerjs_core.DateSystem.Date1900) => {
|
|
2057
|
+
const utcDate = (0, _univerjs_core.excelSerialToDateTime)(value, dateSystem);
|
|
2058
|
+
if (Number.isNaN(utcDate.getTime())) return NaN;
|
|
2059
|
+
return new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate(), utcDate.getUTCHours(), utcDate.getUTCMinutes(), utcDate.getUTCSeconds(), utcDate.getUTCMilliseconds()).getTime();
|
|
2050
2060
|
};
|
|
2051
2061
|
const getValueByType = (value, matrix, context) => {
|
|
2052
2062
|
switch (value.type) {
|
|
@@ -2122,7 +2132,7 @@ const getCacheStyleMatrix = (unitId, subUnitId, rule, context) => {
|
|
|
2122
2132
|
const { accessor } = context;
|
|
2123
2133
|
const conditionalFormattingViewModel = accessor.get(ConditionalFormattingViewModel);
|
|
2124
2134
|
const matrix = new _univerjs_core.ObjectMatrix();
|
|
2125
|
-
rule.ranges.forEach((range) => {
|
|
2135
|
+
getRangesInWorksheet(rule.ranges, context.worksheet).forEach((range) => {
|
|
2126
2136
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
2127
2137
|
const cellCfItem = conditionalFormattingViewModel.getCellCfs(unitId, subUnitId, row, col);
|
|
2128
2138
|
if (cellCfItem) {
|
|
@@ -2184,7 +2194,7 @@ const getColorScaleFromValue = (colorList, value) => {
|
|
|
2184
2194
|
const maxRgb = prefixRgba(maxItem.color.toRgb());
|
|
2185
2195
|
const length = maxItem.value - minItem.value;
|
|
2186
2196
|
const v = (value - minItem.value) / length;
|
|
2187
|
-
|
|
2197
|
+
const rgbResult = [
|
|
2188
2198
|
"r",
|
|
2189
2199
|
"g",
|
|
2190
2200
|
"b",
|
|
@@ -2193,16 +2203,20 @@ const getColorScaleFromValue = (colorList, value) => {
|
|
|
2193
2203
|
const minV = minRgb[key];
|
|
2194
2204
|
obj[key] = (maxRgb[key] - minV) * v + minV;
|
|
2195
2205
|
return obj;
|
|
2196
|
-
}, {})
|
|
2206
|
+
}, {});
|
|
2207
|
+
return new _univerjs_core.ColorKit(rgbResult).toRgbString();
|
|
2197
2208
|
}
|
|
2198
2209
|
} else return colorList[colorList.length - 1].color.toRgbString();
|
|
2199
2210
|
};
|
|
2200
2211
|
const filterRange = (ranges, maxRow, maxCol) => {
|
|
2201
2212
|
return ranges.map((range) => {
|
|
2202
|
-
if (range.startColumn > maxCol || range.startRow > maxRow) return null;
|
|
2213
|
+
if (range.startColumn > maxCol || range.startRow > maxRow || range.endColumn < 0 || range.endRow < 0) return null;
|
|
2203
2214
|
const _range = { ...range };
|
|
2215
|
+
_range.startRow = Math.max(_range.startRow, 0);
|
|
2216
|
+
_range.startColumn = Math.max(_range.startColumn, 0);
|
|
2204
2217
|
_range.endRow = Math.min(_range.endRow, maxRow);
|
|
2205
2218
|
_range.endColumn = Math.min(_range.endColumn, maxCol);
|
|
2219
|
+
if (_range.startRow > _range.endRow || _range.startColumn > _range.endColumn) return null;
|
|
2206
2220
|
return _range;
|
|
2207
2221
|
}).filter((range) => !!range);
|
|
2208
2222
|
};
|
|
@@ -2543,7 +2557,7 @@ for (const key in iconMap) {
|
|
|
2543
2557
|
//#endregion
|
|
2544
2558
|
//#region package.json
|
|
2545
2559
|
var name = "@univerjs/sheets-conditional-formatting";
|
|
2546
|
-
var version = "1.0.0
|
|
2560
|
+
var version = "1.0.0";
|
|
2547
2561
|
|
|
2548
2562
|
//#endregion
|
|
2549
2563
|
//#region src/config/config.ts
|
|
@@ -2568,14 +2582,28 @@ const defaultPluginConfig = {};
|
|
|
2568
2582
|
|
|
2569
2583
|
//#endregion
|
|
2570
2584
|
//#region src/services/conditional-formatting-style-composer.service.ts
|
|
2571
|
-
let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleComposer {
|
|
2585
|
+
let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleComposer extends _univerjs_core.Disposable {
|
|
2572
2586
|
constructor(_conditionalFormattingRuleModel, _conditionalFormattingViewModel) {
|
|
2587
|
+
super();
|
|
2573
2588
|
this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel;
|
|
2574
2589
|
this._conditionalFormattingViewModel = _conditionalFormattingViewModel;
|
|
2590
|
+
_defineProperty(this, "_cache", new _univerjs_core.LRUMap(CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH));
|
|
2591
|
+
this.disposeWithMe(this._conditionalFormattingRuleModel.$ruleChange.subscribe(() => this._cache.clear()));
|
|
2592
|
+
this.disposeWithMe(this._conditionalFormattingViewModel.markDirty$.subscribe(() => this._cache.clear()));
|
|
2593
|
+
this.disposeWithMe(this._conditionalFormattingViewModel.cacheClear$.subscribe(() => this._cache.clear()));
|
|
2594
|
+
}
|
|
2595
|
+
dispose() {
|
|
2596
|
+
this._cache.clear();
|
|
2597
|
+
super.dispose();
|
|
2575
2598
|
}
|
|
2576
2599
|
composeStyle(unitId, subUnitId, row, col) {
|
|
2600
|
+
const cacheKey = `${unitId}_${subUnitId}_${row}_${col}`;
|
|
2601
|
+
if (this._cache.has(cacheKey)) return this._cache.get(cacheKey) ?? null;
|
|
2577
2602
|
const cellCfs = this._conditionalFormattingViewModel.getCellCfs(unitId, subUnitId, row, col);
|
|
2578
|
-
if (!(cellCfs === null || cellCfs === void 0 ? void 0 : cellCfs.length))
|
|
2603
|
+
if (!(cellCfs === null || cellCfs === void 0 ? void 0 : cellCfs.length)) {
|
|
2604
|
+
this._cache.set(cacheKey, null);
|
|
2605
|
+
return null;
|
|
2606
|
+
}
|
|
2579
2607
|
const matchedRules = [];
|
|
2580
2608
|
let stopIfTrueIndex = -1;
|
|
2581
2609
|
for (const cacheItem of cellCfs) {
|
|
@@ -2587,13 +2615,17 @@ let ConditionalFormattingStyleComposer = class ConditionalFormattingStyleCompose
|
|
|
2587
2615
|
});
|
|
2588
2616
|
if (stopIfTrueIndex === -1 && rule.stopIfTrue && this._isRuleMatched(rule, cacheItem.result)) stopIfTrueIndex = matchedRules.length - 1;
|
|
2589
2617
|
}
|
|
2590
|
-
if (!matchedRules.length)
|
|
2618
|
+
if (!matchedRules.length) {
|
|
2619
|
+
this._cache.set(cacheKey, null);
|
|
2620
|
+
return null;
|
|
2621
|
+
}
|
|
2591
2622
|
const effectiveRules = stopIfTrueIndex > -1 ? matchedRules.slice(0, stopIfTrueIndex + 1) : matchedRules;
|
|
2592
2623
|
const result = {};
|
|
2593
2624
|
for (let i = effectiveRules.length - 1; i >= 0; i--) {
|
|
2594
2625
|
const { rule, cacheItem } = effectiveRules[i];
|
|
2595
2626
|
this._mergeComposeResult(result, rule, cacheItem.result);
|
|
2596
2627
|
}
|
|
2628
|
+
this._cache.set(cacheKey, result);
|
|
2597
2629
|
return result;
|
|
2598
2630
|
}
|
|
2599
2631
|
_mergeComposeResult(result, rule, ruleResult) {
|
|
@@ -2957,16 +2989,22 @@ var ConditionalFormattingIcon = class extends _univerjs_engine_render.SheetExten
|
|
|
2957
2989
|
_defineProperty(this, "_paddingRightAndLeft", 2);
|
|
2958
2990
|
_defineProperty(this, "_width", 15);
|
|
2959
2991
|
_defineProperty(this, "_imageMap", /* @__PURE__ */ new Map());
|
|
2992
|
+
_defineProperty(this, "_renderRangeResolver", null);
|
|
2960
2993
|
_defineProperty(this, "uKey", IconUKey);
|
|
2961
2994
|
_defineProperty(this, "Z_INDEX", EXTENSION_Z_INDEX);
|
|
2962
2995
|
_defineProperty(this, "_radius", 1);
|
|
2963
2996
|
this._init();
|
|
2964
2997
|
}
|
|
2998
|
+
setRenderRangeResolver(resolver) {
|
|
2999
|
+
this._renderRangeResolver = resolver;
|
|
3000
|
+
}
|
|
2965
3001
|
draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
|
|
2966
3002
|
const { worksheet } = spreadsheetSkeleton;
|
|
2967
3003
|
if (!worksheet) return false;
|
|
2968
3004
|
const mergeCellRendered = /* @__PURE__ */ new Set();
|
|
2969
|
-
const
|
|
3005
|
+
const sourceRanges = (diffRanges === null || diffRanges === void 0 ? void 0 : diffRanges.length) ? diffRanges : [spreadsheetSkeleton.rowColumnSegment];
|
|
3006
|
+
const renderRanges = this._renderRangeResolver && worksheet.getMergeData().length === 0 ? this._renderRangeResolver(worksheet.getUnitId(), worksheet.getSheetId(), sourceRanges) ?? sourceRanges : sourceRanges;
|
|
3007
|
+
if (!renderRanges.length) return;
|
|
2970
3008
|
ctx.save();
|
|
2971
3009
|
renderRanges.forEach((range) => {
|
|
2972
3010
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
@@ -2996,6 +3034,10 @@ var ConditionalFormattingIcon = class extends _univerjs_engine_render.SheetExten
|
|
|
2996
3034
|
});
|
|
2997
3035
|
ctx.restore();
|
|
2998
3036
|
}
|
|
3037
|
+
dispose() {
|
|
3038
|
+
this._renderRangeResolver = null;
|
|
3039
|
+
super.dispose();
|
|
3040
|
+
}
|
|
2999
3041
|
_init() {
|
|
3000
3042
|
for (const type in iconMap) iconMap[type].forEach((base64, index) => {
|
|
3001
3043
|
const key = this._createKey(type, String(index));
|
|
@@ -3134,5 +3176,4 @@ exports.moveByAnchor = moveByAnchor;
|
|
|
3134
3176
|
exports.removeUndefinedAttr = removeUndefinedAttr;
|
|
3135
3177
|
exports.serialTimeToTimestamp = serialTimeToTimestamp;
|
|
3136
3178
|
exports.setConditionalRuleMutationUndoFactory = setConditionalRuleMutationUndoFactory;
|
|
3137
|
-
exports.toYMD_1900 = toYMD_1900;
|
|
3138
3179
|
exports.transformSupportSymmetryAnchor = transformSupportSymmetryAnchor;
|
package/lib/cjs/locale/ar-SA.js
CHANGED
package/lib/cjs/locale/ca-ES.js
CHANGED
package/lib/cjs/locale/de-DE.js
CHANGED
package/lib/cjs/locale/en-US.js
CHANGED
package/lib/cjs/locale/es-ES.js
CHANGED
package/lib/cjs/locale/fa-IR.js
CHANGED
package/lib/cjs/locale/fr-FR.js
CHANGED
package/lib/cjs/locale/id-ID.js
CHANGED
package/lib/cjs/locale/it-IT.js
CHANGED
package/lib/cjs/locale/ja-JP.js
CHANGED
package/lib/cjs/locale/ko-KR.js
CHANGED
package/lib/cjs/locale/pl-PL.js
CHANGED
package/lib/cjs/locale/pt-BR.js
CHANGED
package/lib/cjs/locale/ru-RU.js
CHANGED
package/lib/cjs/locale/sk-SK.js
CHANGED
package/lib/cjs/locale/vi-VN.js
CHANGED
package/lib/cjs/locale/zh-CN.js
CHANGED
package/lib/cjs/locale/zh-HK.js
CHANGED
package/lib/cjs/locale/zh-TW.js
CHANGED