@univerjs/sheets-conditional-formatting 1.0.0-rc.0 → 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/lib/es/index.js CHANGED
@@ -144,9 +144,7 @@ const moveByAnchor = (start, end, ruleList, get) => {
144
144
  ruleList.splice(endIndex + 1, 0, rule);
145
145
  break;
146
146
  case "self":
147
- case "after":
148
- ruleList.splice(endIndex, 0, rule);
149
- break;
147
+ case "after": ruleList.splice(endIndex, 0, rule);
150
148
  }
151
149
  };
152
150
  /**
@@ -220,7 +218,7 @@ const isAnchorEqual = (anchor1, anchor2) => {
220
218
  const createCfId = () => `${generateRandomId(8)}`;
221
219
 
222
220
  //#endregion
223
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
221
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
224
222
  function _typeof(o) {
225
223
  "@babel/helpers - typeof";
226
224
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -231,7 +229,7 @@ function _typeof(o) {
231
229
  }
232
230
 
233
231
  //#endregion
234
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
232
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
235
233
  function toPrimitive(t, r) {
236
234
  if ("object" != _typeof(t) || !t) return t;
237
235
  var e = t[Symbol.toPrimitive];
@@ -244,14 +242,14 @@ function toPrimitive(t, r) {
244
242
  }
245
243
 
246
244
  //#endregion
247
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
245
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
248
246
  function toPropertyKey(t) {
249
247
  var i = toPrimitive(t, "string");
250
248
  return "symbol" == _typeof(i) ? i : i + "";
251
249
  }
252
250
 
253
251
  //#endregion
254
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
252
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
255
253
  function _defineProperty(e, r, t) {
256
254
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
257
255
  value: t,
@@ -485,7 +483,8 @@ const AddCfCommand = {
485
483
  const undoRedoService = accessor.get(IUndoRedoService);
486
484
  const commandService = accessor.get(ICommandService);
487
485
  const conditionalFormattingRuleModel = accessor.get(ConditionalFormattingRuleModel);
488
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
486
+ const univerInstanceService = accessor.get(IUniverInstanceService);
487
+ const target = getSheetCommandTarget(univerInstanceService, params);
489
488
  if (!target) return false;
490
489
  const { unitId, subUnitId } = target;
491
490
  const cfId = conditionalFormattingRuleModel.createCfId(unitId, subUnitId);
@@ -512,7 +511,7 @@ const AddCfCommand = {
512
511
  };
513
512
 
514
513
  //#endregion
515
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
514
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
516
515
  function __decorateParam(paramIndex, decorator) {
517
516
  return function(target, key) {
518
517
  decorator(target, key, paramIndex);
@@ -520,7 +519,7 @@ function __decorateParam(paramIndex, decorator) {
520
519
  }
521
520
 
522
521
  //#endregion
523
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
522
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
524
523
  function __decorate(decorators, target, key, desc) {
525
524
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
526
525
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -791,7 +790,8 @@ const DeleteCfCommand = {
791
790
  if (!params) return false;
792
791
  const undoRedoService = accessor.get(IUndoRedoService);
793
792
  const commandService = accessor.get(ICommandService);
794
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
793
+ const univerInstanceService = accessor.get(IUniverInstanceService);
794
+ const target = getSheetCommandTarget(univerInstanceService, params);
795
795
  if (!target) return false;
796
796
  const { unitId, subUnitId } = target;
797
797
  const config = {
@@ -859,7 +859,8 @@ const SetCfCommand = {
859
859
  if (!params) return false;
860
860
  const undoRedoService = accessor.get(IUndoRedoService);
861
861
  const commandService = accessor.get(ICommandService);
862
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
862
+ const univerInstanceService = accessor.get(IUniverInstanceService);
863
+ const target = getSheetCommandTarget(univerInstanceService, params);
863
864
  if (!target) return false;
864
865
  const { unitId, subUnitId } = target;
865
866
  const config = {
@@ -882,13 +883,43 @@ const SetCfCommand = {
882
883
  }
883
884
  };
884
885
 
886
+ //#endregion
887
+ //#region src/utils/range.ts
888
+ function getRangeInWorksheet(range, worksheet) {
889
+ const maxRows = worksheet.getMaxRows();
890
+ const maxColumns = worksheet.getMaxColumns();
891
+ if (maxRows <= 0 || maxColumns <= 0) return null;
892
+ const effectiveRange = getIntersectRange(Range.transformRange(range, worksheet), {
893
+ startRow: 0,
894
+ endRow: maxRows - 1,
895
+ startColumn: 0,
896
+ endColumn: maxColumns - 1
897
+ });
898
+ if (!effectiveRange) return null;
899
+ return {
900
+ startRow: effectiveRange.startRow,
901
+ endRow: effectiveRange.endRow,
902
+ startColumn: effectiveRange.startColumn,
903
+ endColumn: effectiveRange.endColumn
904
+ };
905
+ }
906
+ function getRangesInWorksheet(ranges, worksheet) {
907
+ const effectiveRanges = [];
908
+ ranges.forEach((range) => {
909
+ const effectiveRange = getRangeInWorksheet(range, worksheet);
910
+ if (effectiveRange) effectiveRanges.push(effectiveRange);
911
+ });
912
+ return effectiveRanges;
913
+ }
914
+
885
915
  //#endregion
886
916
  //#region src/services/conditional-formatting-formula.service.ts
887
917
  let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaService extends Disposable {
888
- constructor(_registerOtherFormulaService, _conditionalFormattingRuleModel) {
918
+ constructor(_registerOtherFormulaService, _conditionalFormattingRuleModel, _univerInstanceService) {
889
919
  super();
890
920
  this._registerOtherFormulaService = _registerOtherFormulaService;
891
921
  this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel;
922
+ this._univerInstanceService = _univerInstanceService;
892
923
  _defineProperty(this, "_formulaMap", /* @__PURE__ */ new Map());
893
924
  _defineProperty(this, "_result$", new Subject());
894
925
  _defineProperty(this, "result$", this._result$.asObservable());
@@ -917,12 +948,10 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
917
948
  */
918
949
  _registerRuleFormulas(unitId, subUnitId, rule) {
919
950
  switch (rule.rule.type) {
920
- case "highlightCell":
921
- if (rule.rule.subType === "formula") {
922
- const formulaText = rule.rule.value;
923
- if (formulaText) this.registerFormulaWithRange(unitId, subUnitId, rule.cfId, formulaText, rule.ranges);
924
- }
925
- break;
951
+ case "highlightCell": if (rule.rule.subType === "formula") {
952
+ const formulaText = rule.rule.value;
953
+ if (formulaText) this.registerFormulaWithRange(unitId, subUnitId, rule.cfId, formulaText, rule.ranges);
954
+ }
926
955
  }
927
956
  }
928
957
  _initFormulaResultChange() {
@@ -967,10 +996,15 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
967
996
  startColumn: 0,
968
997
  endColumn: 0
969
998
  }]) {
999
+ var _this$_univerInstance;
970
1000
  const formulaMap = this._ensureSubunitFormulaMap(unitId, subUnitId);
971
1001
  const cfFormulaId = this.createCFormulaId(cfId, formulaText);
972
1002
  if (formulaMap.getValue(cfFormulaId, ["id"])) return;
973
- const sortedRanges = [...ranges].sort((a, b) => a.startRow !== b.startRow ? a.startRow - b.startRow : a.startColumn - b.startColumn);
1003
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
1004
+ if (!worksheet) return;
1005
+ const effectiveRanges = getRangesInWorksheet(ranges, worksheet);
1006
+ if (!effectiveRanges.length) return;
1007
+ const sortedRanges = effectiveRanges.sort((a, b) => a.startRow !== b.startRow ? a.startRow - b.startRow : a.startColumn - b.startColumn);
974
1008
  const formulaId = this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaText, sortedRanges, void 0, OtherFormulaBizType.CONDITIONAL_FORMATTING, cfId);
975
1009
  formulaMap.addValue({
976
1010
  formulaText,
@@ -1057,7 +1091,11 @@ let ConditionalFormattingFormulaService = class ConditionalFormattingFormulaServ
1057
1091
  return `${cfId}_${formulaText}`;
1058
1092
  }
1059
1093
  };
1060
- ConditionalFormattingFormulaService = __decorate([__decorateParam(0, Inject(RegisterOtherFormulaService)), __decorateParam(1, Inject(ConditionalFormattingRuleModel))], ConditionalFormattingFormulaService);
1094
+ ConditionalFormattingFormulaService = __decorate([
1095
+ __decorateParam(0, Inject(RegisterOtherFormulaService)),
1096
+ __decorateParam(1, Inject(ConditionalFormattingRuleModel)),
1097
+ __decorateParam(2, IUniverInstanceService)
1098
+ ], ConditionalFormattingFormulaService);
1061
1099
 
1062
1100
  //#endregion
1063
1101
  //#region src/models/calculate-unit-v2/base-calculate-unit.ts
@@ -1388,28 +1426,29 @@ var DataBarCalculateUnit = class extends BaseCalculateUnit {
1388
1426
  isGradient,
1389
1427
  isShowValue
1390
1428
  };
1391
- } else if (min < 0 && max > 0) if (value > 0) {
1392
- const v = getSafeValue(Math.min(value / max, 1) * 100);
1393
- if (v === 0) return;
1394
- return {
1395
- color: ruleConfig.config.positiveColor || "#ffbe38",
1396
- startPoint,
1397
- value: v,
1398
- isGradient,
1399
- isShowValue
1400
- };
1401
- } else {
1402
- const v = getSafeValue(Math.min(Math.abs(value) / Math.abs(min), 1) * 100);
1403
- if (v === 0) return;
1404
- return {
1405
- color: ruleConfig.config.nativeColor || "#abd91a",
1406
- startPoint,
1407
- value: -v,
1408
- isGradient,
1409
- isShowValue
1410
- };
1411
- }
1412
- else if (min >= 0 && max > 0) {
1429
+ } else if (min < 0 && max > 0) {
1430
+ if (value > 0) {
1431
+ const v = getSafeValue(Math.min(value / max, 1) * 100);
1432
+ if (v === 0) return;
1433
+ return {
1434
+ color: ruleConfig.config.positiveColor || "#ffbe38",
1435
+ startPoint,
1436
+ value: v,
1437
+ isGradient,
1438
+ isShowValue
1439
+ };
1440
+ } else {
1441
+ const v = getSafeValue(Math.min(Math.abs(value) / Math.abs(min), 1) * 100);
1442
+ if (v === 0) return;
1443
+ return {
1444
+ color: ruleConfig.config.nativeColor || "#abd91a",
1445
+ startPoint,
1446
+ value: -v,
1447
+ isGradient,
1448
+ isShowValue
1449
+ };
1450
+ }
1451
+ } else if (min >= 0 && max > 0) {
1413
1452
  const length = max - min;
1414
1453
  const startPoint = 0;
1415
1454
  const v = getSafeValue((1 - (max - value) / length) * 100);
@@ -1461,7 +1500,8 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
1461
1500
  const cacheMap = /* @__PURE__ */ new Map();
1462
1501
  ranges.forEach((range) => {
1463
1502
  Range.foreach(range, (row, col) => {
1464
- const v = getCellValue(context.getCellValue(row, col));
1503
+ const cell = context.getCellValue(row, col);
1504
+ const v = getCellValue(cell);
1465
1505
  if (!isNullable(v)) {
1466
1506
  const cache = cacheMap.get(v);
1467
1507
  if (cache) cacheMap.set(v, cache + 1);
@@ -1603,18 +1643,19 @@ var HighlightCellCalculateUnit = class extends BaseCalculateUnit {
1603
1643
  const run = () => {
1604
1644
  switch (ruleConfig.subType) {
1605
1645
  case "number": {
1606
- const v = cellValue && Number(cellValue.v);
1607
- const isNumber = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === CellValueType.NUMBER;
1608
1646
  const subRuleConfig = ruleConfig;
1609
- if (!isNumber) {
1610
- if (["notEqual", "notBetween"].includes(subRuleConfig.operator)) return true;
1611
- return false;
1612
- }
1613
- if (isNullable(v) || Number.isNaN(v)) return;
1647
+ const value = cellValue === null || cellValue === void 0 ? void 0 : cellValue.v;
1648
+ if ((cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== CellValueType.FORCE_STRING && ERROR_TYPE_SET.has(value)) return false;
1649
+ if (value != null && ((cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === CellValueType.BOOLEAN || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) !== CellValueType.NUMBER && typeof value !== "number")) return [
1650
+ "notEqual",
1651
+ "notBetween",
1652
+ "greaterThan",
1653
+ "greaterThanOrEqual"
1654
+ ].includes(subRuleConfig.operator);
1614
1655
  return compareWithNumber({
1615
1656
  operator: subRuleConfig.operator,
1616
- value: subRuleConfig.value || 0
1617
- }, v || 0);
1657
+ value: subRuleConfig.value ?? 0
1658
+ }, Number(value ?? 0));
1618
1659
  }
1619
1660
  case "text": {
1620
1661
  const subRuleConfig = ruleConfig;
@@ -1797,7 +1838,7 @@ var IconSetCalculateUnit = class extends BaseCalculateUnit {
1797
1838
 
1798
1839
  //#endregion
1799
1840
  //#region src/models/conditional-formatting-view-model.ts
1800
- const CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH = 1e3 * 3 * 3;
1841
+ const CONDITIONAL_FORMATTING_VIEWPORT_CACHE_LENGTH = 9e3;
1801
1842
  let ConditionalFormattingViewModel = class ConditionalFormattingViewModel extends Disposable {
1802
1843
  constructor(_injector, _conditionalFormattingRuleModel, _conditionalFormattingRangeIndexModel, _conditionalFormattingFormulaService, _univerInstanceService) {
1803
1844
  super();
@@ -2090,7 +2131,7 @@ const getCacheStyleMatrix = (unitId, subUnitId, rule, context) => {
2090
2131
  const { accessor } = context;
2091
2132
  const conditionalFormattingViewModel = accessor.get(ConditionalFormattingViewModel);
2092
2133
  const matrix = new ObjectMatrix();
2093
- rule.ranges.forEach((range) => {
2134
+ getRangesInWorksheet(rule.ranges, context.worksheet).forEach((range) => {
2094
2135
  Range.foreach(range, (row, col) => {
2095
2136
  const cellCfItem = conditionalFormattingViewModel.getCellCfs(unitId, subUnitId, row, col);
2096
2137
  if (cellCfItem) {
@@ -2152,7 +2193,7 @@ const getColorScaleFromValue = (colorList, value) => {
2152
2193
  const maxRgb = prefixRgba(maxItem.color.toRgb());
2153
2194
  const length = maxItem.value - minItem.value;
2154
2195
  const v = (value - minItem.value) / length;
2155
- return new ColorKit([
2196
+ const rgbResult = [
2156
2197
  "r",
2157
2198
  "g",
2158
2199
  "b",
@@ -2161,16 +2202,20 @@ const getColorScaleFromValue = (colorList, value) => {
2161
2202
  const minV = minRgb[key];
2162
2203
  obj[key] = (maxRgb[key] - minV) * v + minV;
2163
2204
  return obj;
2164
- }, {})).toRgbString();
2205
+ }, {});
2206
+ return new ColorKit(rgbResult).toRgbString();
2165
2207
  }
2166
2208
  } else return colorList[colorList.length - 1].color.toRgbString();
2167
2209
  };
2168
2210
  const filterRange = (ranges, maxRow, maxCol) => {
2169
2211
  return ranges.map((range) => {
2170
- if (range.startColumn > maxCol || range.startRow > maxRow) return null;
2212
+ if (range.startColumn > maxCol || range.startRow > maxRow || range.endColumn < 0 || range.endRow < 0) return null;
2171
2213
  const _range = { ...range };
2214
+ _range.startRow = Math.max(_range.startRow, 0);
2215
+ _range.startColumn = Math.max(_range.startColumn, 0);
2172
2216
  _range.endRow = Math.min(_range.endRow, maxRow);
2173
2217
  _range.endColumn = Math.min(_range.endColumn, maxCol);
2218
+ if (_range.startRow > _range.endRow || _range.startColumn > _range.endColumn) return null;
2174
2219
  return _range;
2175
2220
  }).filter((range) => !!range);
2176
2221
  };
@@ -2511,7 +2556,7 @@ for (const key in iconMap) {
2511
2556
  //#endregion
2512
2557
  //#region package.json
2513
2558
  var name = "@univerjs/sheets-conditional-formatting";
2514
- var version = "1.0.0-rc.0";
2559
+ var version = "1.0.0";
2515
2560
 
2516
2561
  //#endregion
2517
2562
  //#region src/config/config.ts
package/lib/facade.js CHANGED
@@ -3,7 +3,7 @@ import { AddCfCommand, CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperat
3
3
  import { FRange, FWorksheet } from "@univerjs/sheets/facade";
4
4
  import { FEnum } from "@univerjs/core/facade";
5
5
 
6
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
6
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
7
7
  function _typeof(o) {
8
8
  "@babel/helpers - typeof";
9
9
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -14,7 +14,7 @@ function _typeof(o) {
14
14
  }
15
15
 
16
16
  //#endregion
17
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
17
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
18
18
  function toPrimitive(t, r) {
19
19
  if ("object" != _typeof(t) || !t) return t;
20
20
  var e = t[Symbol.toPrimitive];
@@ -27,14 +27,14 @@ function toPrimitive(t, r) {
27
27
  }
28
28
 
29
29
  //#endregion
30
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
30
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
31
31
  function toPropertyKey(t) {
32
32
  var i = toPrimitive(t, "string");
33
33
  return "symbol" == _typeof(i) ? i : i + "";
34
34
  }
35
35
 
36
36
  //#endregion
37
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
37
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
38
38
  function _defineProperty(e, r, t) {
39
39
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
40
40
  value: t,
@@ -409,11 +409,13 @@ var ConditionalFormatHighlightRuleBuilder = class ConditionalFormatHighlightRule
409
409
  */
410
410
  setBackground(color) {
411
411
  var _this$_ruleConfig;
412
- if (((_this$_ruleConfig = this._ruleConfig) === null || _this$_ruleConfig === void 0 ? void 0 : _this$_ruleConfig.type) === CFRuleType.highlightCell) if (color) {
413
- this._ensureAttr(this._ruleConfig, ["style", "bg"]);
414
- const colorKit = new ColorKit(color);
415
- this._ruleConfig.style.bg.rgb = colorKit.toRgbString();
416
- } else delete this._ruleConfig.style.bg;
412
+ if (((_this$_ruleConfig = this._ruleConfig) === null || _this$_ruleConfig === void 0 ? void 0 : _this$_ruleConfig.type) === CFRuleType.highlightCell) {
413
+ if (color) {
414
+ this._ensureAttr(this._ruleConfig, ["style", "bg"]);
415
+ const colorKit = new ColorKit(color);
416
+ this._ruleConfig.style.bg.rgb = colorKit.toRgbString();
417
+ } else delete this._ruleConfig.style.bg;
418
+ }
417
419
  return this;
418
420
  }
419
421
  /**
@@ -466,11 +468,13 @@ var ConditionalFormatHighlightRuleBuilder = class ConditionalFormatHighlightRule
466
468
  */
467
469
  setFontColor(color) {
468
470
  var _this$_ruleConfig3;
469
- if (((_this$_ruleConfig3 = this._ruleConfig) === null || _this$_ruleConfig3 === void 0 ? void 0 : _this$_ruleConfig3.type) === CFRuleType.highlightCell) if (color) {
470
- const colorKit = new ColorKit(color);
471
- this._ensureAttr(this._ruleConfig, ["style", "cl"]);
472
- this._ruleConfig.style.cl.rgb = colorKit.toRgbString();
473
- } else delete this._ruleConfig.style.cl;
471
+ if (((_this$_ruleConfig3 = this._ruleConfig) === null || _this$_ruleConfig3 === void 0 ? void 0 : _this$_ruleConfig3.type) === CFRuleType.highlightCell) {
472
+ if (color) {
473
+ const colorKit = new ColorKit(color);
474
+ this._ensureAttr(this._ruleConfig, ["style", "cl"]);
475
+ this._ruleConfig.style.cl.rgb = colorKit.toRgbString();
476
+ } else delete this._ruleConfig.style.cl;
477
+ }
474
478
  return this;
475
479
  }
476
480
  /**