@univerjs/sheets-conditional-formatting 0.3.0-alpha.1 → 0.3.0-nightly.202410111606

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
@@ -2,12 +2,12 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { Tools, Inject, Injector, ObjectMatrix, Range, CommandType, ICommandService, Disposable, toDisposable, RefAlias, CellValueType, BooleanNumber, ColorKit, Rectangle, createInterceptorKey, OnLifecycle, LifecycleStages, IUniverInstanceService, IResourceManagerService, InterceptorManager, UniverInstanceType, Plugin, IConfigService } from "@univerjs/core";
5
+ import { Tools, Inject, Injector, ObjectMatrix, Range, CommandType, ICommandService, Disposable, toDisposable, RefAlias, CellValueType, BooleanNumber, ColorKit, Rectangle, createInterceptorKey, IUniverInstanceService, IResourceManagerService, InterceptorManager, UniverInstanceType, Plugin, IConfigService } from "@univerjs/core";
6
6
  import { Subject, Observable } from "rxjs";
7
7
  import { bufferTime, filter, map } from "rxjs/operators";
8
8
  import { SheetInterceptorService, RemoveSheetCommand, ReorderRangeMutation, MoveRangeMutation, MoveColsMutation, MoveRowsMutation, InsertRowMutation, RemoveRowMutation, RemoveColMutation, InsertColMutation, SetRangeValuesMutation } from "@univerjs/sheets";
9
+ import { isObject, SpreadsheetExtensionRegistry, SheetExtension, FIX_ONE_PIXEL_BLUR_OFFSET } from "@univerjs/engine-render";
9
10
  import { IActiveDirtyManagerService, SetFormulaCalculationResultMutation, SetOtherFormulaMutation, RemoveOtherFormulaMutation, BooleanValue, LexerTreeBuilder, sequenceNodeType, deserializeRangeWithSheet, serializeRange, generateStringWithSequence, ERROR_TYPE_SET } from "@univerjs/engine-formula";
10
- import { SpreadsheetExtensionRegistry, SheetExtension, FIX_ONE_PIXEL_BLUR_OFFSET, isObject } from "@univerjs/engine-render";
11
11
  import dayjs from "dayjs";
12
12
  const SHEET_CONDITIONAL_FORMATTING_PLUGIN = "SHEET_CONDITIONAL_FORMATTING_PLUGIN";
13
13
  var CFTextOperator = /* @__PURE__ */ ((CFTextOperator2) => (CFTextOperator2.beginsWith = "beginsWith", CFTextOperator2.endsWith = "endsWith", CFTextOperator2.containsText = "containsText", CFTextOperator2.notContainsText = "notContainsText", CFTextOperator2.equal = "equal", CFTextOperator2.notEqual = "notEqual", CFTextOperator2.containsBlanks = "containsBlanks", CFTextOperator2.notContainsBlanks = "notContainsBlanks", CFTextOperator2.containsErrors = "containsErrors", CFTextOperator2.notContainsErrors = "notContainsErrors", CFTextOperator2))(CFTextOperator || {}), CFTimePeriodOperator = /* @__PURE__ */ ((CFTimePeriodOperator2) => (CFTimePeriodOperator2.today = "today", CFTimePeriodOperator2.yesterday = "yesterday", CFTimePeriodOperator2.tomorrow = "tomorrow", CFTimePeriodOperator2.last7Days = "last7Days", CFTimePeriodOperator2.thisMonth = "thisMonth", CFTimePeriodOperator2.lastMonth = "lastMonth", CFTimePeriodOperator2.nextMonth = "nextMonth", CFTimePeriodOperator2.thisWeek = "thisWeek", CFTimePeriodOperator2.lastWeek = "lastWeek", CFTimePeriodOperator2.nextWeek = "nextWeek", CFTimePeriodOperator2))(CFTimePeriodOperator || {}), CFNumberOperator = /* @__PURE__ */ ((CFNumberOperator2) => (CFNumberOperator2.greaterThan = "greaterThan", CFNumberOperator2.greaterThanOrEqual = "greaterThanOrEqual", CFNumberOperator2.lessThan = "lessThan", CFNumberOperator2.lessThanOrEqual = "lessThanOrEqual", CFNumberOperator2.notBetween = "notBetween", CFNumberOperator2.between = "between", CFNumberOperator2.equal = "equal", CFNumberOperator2.notEqual = "notEqual", CFNumberOperator2))(CFNumberOperator || {}), CFRuleType = /* @__PURE__ */ ((CFRuleType2) => (CFRuleType2.highlightCell = "highlightCell", CFRuleType2.dataBar = "dataBar", CFRuleType2.colorScale = "colorScale", CFRuleType2.iconSet = "iconSet", CFRuleType2))(CFRuleType || {}), CFSubRuleType = /* @__PURE__ */ ((CFSubRuleType2) => (CFSubRuleType2.uniqueValues = "uniqueValues", CFSubRuleType2.duplicateValues = "duplicateValues", CFSubRuleType2.rank = "rank", CFSubRuleType2.text = "text", CFSubRuleType2.timePeriod = "timePeriod", CFSubRuleType2.number = "number", CFSubRuleType2.average = "average", CFSubRuleType2.formula = "formula", CFSubRuleType2))(CFSubRuleType || {}), CFValueType = /* @__PURE__ */ ((CFValueType2) => (CFValueType2.num = "num", CFValueType2.min = "min", CFValueType2.max = "max", CFValueType2.percent = "percent", CFValueType2.percentile = "percentile", CFValueType2.formula = "formula", CFValueType2))(CFValueType || {});
@@ -484,16 +484,7 @@ for (const key in iconMap) {
484
484
  const v = iconMap[key];
485
485
  Object.freeze(v);
486
486
  }
487
- const EMPTY_ICON_TYPE = "EMPTY_ICON_TYPE", AddConditionalRuleMutationUndoFactory = /* @__PURE__ */ __name((accessor, param) => ({ id: DeleteConditionalRuleMutation.id, params: { unitId: param.unitId, subUnitId: param.subUnitId, cfId: param.rule.cfId } }), "AddConditionalRuleMutationUndoFactory"), AddConditionalRuleMutation = {
488
- type: CommandType.MUTATION,
489
- id: "sheet.mutation.add-conditional-rule",
490
- handler(accessor, params) {
491
- if (!params)
492
- return !1;
493
- const { unitId, subUnitId, rule } = params;
494
- return accessor.get(ConditionalFormattingRuleModel).addRule(unitId, subUnitId, rule), !0;
495
- }
496
- }, MoveConditionalRuleMutation = {
487
+ const EMPTY_ICON_TYPE = "EMPTY_ICON_TYPE", MoveConditionalRuleMutation = {
497
488
  type: CommandType.MUTATION,
498
489
  id: "sheet.mutation.move-conditional-rule",
499
490
  handler(accessor, params) {
@@ -547,13 +538,44 @@ const EMPTY_ICON_TYPE = "EMPTY_ICON_TYPE", AddConditionalRuleMutationUndoFactory
547
538
  const { unitId, subUnitId, cfId } = params;
548
539
  return accessor.get(ConditionalFormattingRuleModel).deleteRule(unitId, subUnitId, cfId), !0;
549
540
  }
541
+ }, AddConditionalRuleMutationUndoFactory = /* @__PURE__ */ __name((accessor, param) => ({ id: DeleteConditionalRuleMutation.id, params: { unitId: param.unitId, subUnitId: param.subUnitId, cfId: param.rule.cfId } }), "AddConditionalRuleMutationUndoFactory"), AddConditionalRuleMutation = {
542
+ type: CommandType.MUTATION,
543
+ id: "sheet.mutation.add-conditional-rule",
544
+ handler(accessor, params) {
545
+ if (!params)
546
+ return !1;
547
+ const { unitId, subUnitId, rule } = params;
548
+ return accessor.get(ConditionalFormattingRuleModel).addRule(unitId, subUnitId, rule), !0;
549
+ }
550
550
  }, ConditionalFormattingFormulaMarkDirty = {
551
551
  type: CommandType.MUTATION,
552
552
  id: "sheet.mutation.conditional-formatting-formula-mark-dirty",
553
553
  handler() {
554
554
  return !0;
555
555
  }
556
- };
556
+ }, SetConditionalRuleMutation = {
557
+ type: CommandType.MUTATION,
558
+ id: "sheet.mutation.set-conditional-rule",
559
+ handler(accessor, params) {
560
+ if (!params)
561
+ return !1;
562
+ const { unitId, subUnitId, rule } = params, cfId = params.cfId || params.rule.cfId;
563
+ return accessor.get(ConditionalFormattingRuleModel).setRule(unitId, subUnitId, rule, cfId), !0;
564
+ }
565
+ }, setConditionalRuleMutationUndoFactory = /* @__PURE__ */ __name((accessor, param) => {
566
+ const conditionalFormattingRuleModel = accessor.get(ConditionalFormattingRuleModel), { unitId, subUnitId } = param, cfId = param.cfId || param.rule.cfId, rule = conditionalFormattingRuleModel.getRule(unitId, subUnitId, cfId);
567
+ return rule ? [
568
+ {
569
+ id: SetConditionalRuleMutation.id,
570
+ params: {
571
+ unitId,
572
+ subUnitId,
573
+ cfId,
574
+ rule: Tools.deepClone(rule)
575
+ }
576
+ }
577
+ ] : [];
578
+ }, "setConditionalRuleMutationUndoFactory"), PLUGIN_CONFIG_KEY = "ssheets-conditional-formatting.config", defaultPluginConfig = {};
557
579
  var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
558
580
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
559
581
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
@@ -725,58 +747,6 @@ ConditionalFormattingFormulaService = __decorateClass$2([
725
747
  __decorateParam$2(3, Inject(ConditionalFormattingViewModel)),
726
748
  __decorateParam$2(4, Inject(ConditionalFormattingRuleModel))
727
749
  ], ConditionalFormattingFormulaService);
728
- const dataBarUKey = "sheet-conditional-rule-data-bar", defaultDataBarPositiveColor = "#ffbe38", defaultDataBarNativeColor = "#abd91a", EXTENSION_Z_INDEX$1 = 34, _DataBar = class _DataBar extends SheetExtension {
729
- constructor() {
730
- super(...arguments);
731
- __publicField(this, "_paddingRightAndLeft", 2);
732
- __publicField(this, "_paddingTopAndBottom", 2);
733
- __publicField(this, "uKey", dataBarUKey);
734
- __publicField(this, "Z_INDEX", EXTENSION_Z_INDEX$1);
735
- __publicField(this, "_radius", 1);
736
- }
737
- // eslint-disable-next-line max-lines-per-function
738
- draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
739
- const { worksheet } = spreadsheetSkeleton;
740
- if (!worksheet)
741
- return !1;
742
- ctx.save(), Range.foreach(spreadsheetSkeleton.rowColumnSegment, (row, col) => {
743
- if (!worksheet.getRowVisible(row) || !worksheet.getColVisible(col))
744
- return;
745
- const cellData = worksheet.getCell(row, col);
746
- if (cellData && cellData.dataBar) {
747
- const { color, value, startPoint, isGradient } = cellData.dataBar, cellInfo = spreadsheetSkeleton.getCellByIndexWithNoHeader(row, col);
748
- let { isMerged, isMergedMainCell, mergeInfo, startY, endY, startX, endX } = cellInfo;
749
- if (isMerged || (isMergedMainCell && (startY = mergeInfo.startY, endY = mergeInfo.endY, startX = mergeInfo.startX, endX = mergeInfo.endX), !this.isRenderDiffRangesByCell(mergeInfo, diffRanges)))
750
- return;
751
- const borderWidth = endX - startX, borderHeight = endY + FIX_ONE_PIXEL_BLUR_OFFSET - startY, width = borderWidth - this._paddingRightAndLeft * 2, height = borderHeight - this._paddingTopAndBottom * 2;
752
- if (value > 0) {
753
- const dataBarWidth = Math.max(width * (1 - startPoint / 100) * value / 100, 1), x0 = startX + this._paddingRightAndLeft + startPoint / 100 * width, y0 = startY + this._paddingTopAndBottom;
754
- if (isGradient) {
755
- const gradient = ctx.createLinearGradient(x0, y0, x0 + dataBarWidth, y0);
756
- gradient.addColorStop(0, color), gradient.addColorStop(1, "rgb(255 255 255)"), ctx.fillStyle = gradient, ctx.strokeStyle = color, ctx.lineWidth = 1;
757
- } else
758
- ctx.fillStyle = color;
759
- this._drawRectWithRoundedCorner(ctx, x0, y0, dataBarWidth, height, !1, !0, !0, !1), isGradient && ctx.stroke();
760
- } else {
761
- const dataBarWidth = Math.max(width * startPoint / 100 * Math.abs(value) / 100, 1), x0 = startX + this._paddingRightAndLeft + startPoint / 100 * width - dataBarWidth, y0 = startY + this._paddingTopAndBottom;
762
- if (isGradient) {
763
- const gradient = ctx.createLinearGradient(x0, y0, x0 + dataBarWidth, y0);
764
- gradient.addColorStop(0, "rgb(255 255 255)"), gradient.addColorStop(1, color), ctx.fillStyle = gradient, ctx.strokeStyle = color, ctx.lineWidth = 1;
765
- } else
766
- ctx.fillStyle = color;
767
- this._drawRectWithRoundedCorner(ctx, x0, y0, dataBarWidth, height, !0, !1, !1, !0), isGradient && ctx.stroke();
768
- }
769
- }
770
- }), ctx.restore();
771
- }
772
- _drawRectWithRoundedCorner(ctx, x, y, width, height, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius) {
773
- const radius = this._radius;
774
- !height || !width || (ctx.beginPath(), ctx.moveTo(x + radius, y), ctx.lineTo(x + width - radius, y), topRightRadius ? ctx.arcTo(x + width, y, x + width, y + radius, radius) : ctx.lineTo(x + width, y), ctx.lineTo(x + width, y + height - radius), bottomRightRadius ? ctx.arcTo(x + width, y + height, x + width - radius, y + height, radius) : ctx.lineTo(x + width, y + height), ctx.lineTo(x + radius, y + height), bottomLeftRadius ? ctx.arcTo(x, y + height, x, y + height - radius, radius) : ctx.lineTo(x, y + height), ctx.lineTo(x, y + radius), topLeftRadius ? ctx.arcTo(x, y, x + radius, y, radius) : ctx.lineTo(x, y), ctx.closePath(), ctx.fill());
775
- }
776
- };
777
- __name(_DataBar, "DataBar");
778
- let DataBar = _DataBar;
779
- SpreadsheetExtensionRegistry.add(DataBar);
780
750
  function isFloatsEqual(a, b) {
781
751
  return Math.abs(a - b) < Number.EPSILON;
782
752
  }
@@ -951,7 +921,94 @@ const serialTimeToTimestamp = /* @__PURE__ */ __name((value) => {
951
921
  return null;
952
922
  const _range = { ...range };
953
923
  return _range.endRow = Math.min(_range.endRow, maxRow), _range.endColumn = Math.min(_range.endColumn, maxCol), _range;
954
- }).filter((range) => !!range), "filterRange"), EMPTY_STYLE = {};
924
+ }).filter((range) => !!range), "filterRange"), emptyStyle = "", colorScaleCellCalculateUnit = {
925
+ type: CFRuleType.colorScale,
926
+ handle: /* @__PURE__ */ __name(async (rule, context) => {
927
+ var _a5;
928
+ const ruleConfig = rule.rule, conditionalFormattingFormulaService = context.accessor.get(ConditionalFormattingFormulaService), { worksheet } = context, matrix = new ObjectMatrix(), ranges = filterRange(rule.ranges, worksheet.getMaxRows() - 1, worksheet.getMaxColumns() - 1);
929
+ ranges.forEach((range) => {
930
+ Range.foreach(range, (row, col) => {
931
+ const cell2 = worksheet == null ? void 0 : worksheet.getCellRaw(row, col), v = cell2 && cell2.v;
932
+ if (!isNullable(v) && (cell2 == null ? void 0 : cell2.t) === CellValueType.NUMBER) {
933
+ const _value = Number(v);
934
+ !Number.isNaN(_value) && matrix.setValue(row, col, _value);
935
+ }
936
+ });
937
+ });
938
+ const computeResult = new ObjectMatrix();
939
+ ranges.forEach((range) => {
940
+ Range.foreach(range, (row, col) => {
941
+ computeResult.setValue(row, col, emptyStyle);
942
+ });
943
+ });
944
+ const _configList = [...ruleConfig.config].sort((a, b) => a.index - b.index).map((config) => ({
945
+ value: getValueByType(config.value, matrix, { ...context, cfId: rule.cfId }),
946
+ color: new ColorKit(config.color)
947
+ }));
948
+ if (_configList.some((item) => isObject(item.value) ? item.value.status !== FormulaResultStatus.SUCCESS : !1))
949
+ return (_a5 = conditionalFormattingFormulaService.getCache(context.unitId, context.subUnitId, rule.cfId)) != null ? _a5 : computeResult;
950
+ const colorList = _configList.map((item) => item.color).reduce((result, color, index) => (result.result.push({ color, value: result.sortValue[index] }), result), {
951
+ result: [],
952
+ sortValue: _configList.map((item) => item.value.result).sort((a, b) => a - b)
953
+ }).result;
954
+ return colorList.length <= 1 || matrix.forValue((row, col, value) => {
955
+ const color = getColorScaleFromValue(colorList, value);
956
+ color && computeResult.setValue(row, col, color);
957
+ }), computeResult;
958
+ }, "handle")
959
+ }, dataBarUKey = "sheet-conditional-rule-data-bar", defaultDataBarPositiveColor = "#ffbe38", defaultDataBarNativeColor = "#abd91a", EXTENSION_Z_INDEX$1 = 34, _DataBar = class _DataBar extends SheetExtension {
960
+ constructor() {
961
+ super(...arguments);
962
+ __publicField(this, "_paddingRightAndLeft", 2);
963
+ __publicField(this, "_paddingTopAndBottom", 2);
964
+ __publicField(this, "uKey", dataBarUKey);
965
+ __publicField(this, "Z_INDEX", EXTENSION_Z_INDEX$1);
966
+ __publicField(this, "_radius", 1);
967
+ }
968
+ // eslint-disable-next-line max-lines-per-function
969
+ draw(ctx, _parentScale, spreadsheetSkeleton, diffRanges) {
970
+ const { worksheet } = spreadsheetSkeleton;
971
+ if (!worksheet)
972
+ return !1;
973
+ ctx.save(), Range.foreach(spreadsheetSkeleton.rowColumnSegment, (row, col) => {
974
+ if (!worksheet.getRowVisible(row) || !worksheet.getColVisible(col))
975
+ return;
976
+ const cellData = worksheet.getCell(row, col);
977
+ if (cellData && cellData.dataBar) {
978
+ const { color, value, startPoint, isGradient } = cellData.dataBar, cellInfo = spreadsheetSkeleton.getCellByIndexWithNoHeader(row, col);
979
+ let { isMerged, isMergedMainCell, mergeInfo, startY, endY, startX, endX } = cellInfo;
980
+ if (isMerged || (isMergedMainCell && (startY = mergeInfo.startY, endY = mergeInfo.endY, startX = mergeInfo.startX, endX = mergeInfo.endX), !this.isRenderDiffRangesByCell(mergeInfo, diffRanges)))
981
+ return;
982
+ const borderWidth = endX - startX, borderHeight = endY + FIX_ONE_PIXEL_BLUR_OFFSET - startY, width = borderWidth - this._paddingRightAndLeft * 2, height = borderHeight - this._paddingTopAndBottom * 2;
983
+ if (value > 0) {
984
+ const dataBarWidth = Math.max(width * (1 - startPoint / 100) * value / 100, 1), x0 = startX + this._paddingRightAndLeft + startPoint / 100 * width, y0 = startY + this._paddingTopAndBottom;
985
+ if (isGradient) {
986
+ const gradient = ctx.createLinearGradient(x0, y0, x0 + dataBarWidth, y0);
987
+ gradient.addColorStop(0, color), gradient.addColorStop(1, "rgb(255 255 255)"), ctx.fillStyle = gradient, ctx.strokeStyle = color, ctx.lineWidth = 1;
988
+ } else
989
+ ctx.fillStyle = color;
990
+ this._drawRectWithRoundedCorner(ctx, x0, y0, dataBarWidth, height, !1, !0, !0, !1), isGradient && ctx.stroke();
991
+ } else {
992
+ const dataBarWidth = Math.max(width * startPoint / 100 * Math.abs(value) / 100, 1), x0 = startX + this._paddingRightAndLeft + startPoint / 100 * width - dataBarWidth, y0 = startY + this._paddingTopAndBottom;
993
+ if (isGradient) {
994
+ const gradient = ctx.createLinearGradient(x0, y0, x0 + dataBarWidth, y0);
995
+ gradient.addColorStop(0, "rgb(255 255 255)"), gradient.addColorStop(1, color), ctx.fillStyle = gradient, ctx.strokeStyle = color, ctx.lineWidth = 1;
996
+ } else
997
+ ctx.fillStyle = color;
998
+ this._drawRectWithRoundedCorner(ctx, x0, y0, dataBarWidth, height, !0, !1, !1, !0), isGradient && ctx.stroke();
999
+ }
1000
+ }
1001
+ }), ctx.restore();
1002
+ }
1003
+ _drawRectWithRoundedCorner(ctx, x, y, width, height, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius) {
1004
+ const radius = this._radius;
1005
+ !height || !width || (ctx.beginPath(), ctx.moveTo(x + radius, y), ctx.lineTo(x + width - radius, y), topRightRadius ? ctx.arcTo(x + width, y, x + width, y + radius, radius) : ctx.lineTo(x + width, y), ctx.lineTo(x + width, y + height - radius), bottomRightRadius ? ctx.arcTo(x + width, y + height, x + width - radius, y + height, radius) : ctx.lineTo(x + width, y + height), ctx.lineTo(x + radius, y + height), bottomLeftRadius ? ctx.arcTo(x, y + height, x, y + height - radius, radius) : ctx.lineTo(x, y + height), ctx.lineTo(x, y + radius), topLeftRadius ? ctx.arcTo(x, y, x + radius, y, radius) : ctx.lineTo(x, y), ctx.closePath(), ctx.fill());
1006
+ }
1007
+ };
1008
+ __name(_DataBar, "DataBar");
1009
+ let DataBar = _DataBar;
1010
+ SpreadsheetExtensionRegistry.add(DataBar);
1011
+ const EMPTY_STYLE = {};
955
1012
  Object.freeze(EMPTY_STYLE);
956
1013
  const dataBarCellCalculateUnit = {
957
1014
  type: CFRuleType.dataBar,
@@ -1058,8 +1115,8 @@ const dataBarCellCalculateUnit = {
1058
1115
  cell2 && cell2.t === CellValueType.NUMBER && v !== void 0 && allValue.push(Number(v) || 0);
1059
1116
  });
1060
1117
  }), allValue.sort((a, b) => b - a);
1061
- const configRule = rule.rule, targetIndex = configRule.isPercent ? Math.round(Math.max(Math.min(configRule.value, 100), 0) / 100 * allValue.length) : Math.round(Math.max(Math.min(configRule.value, allValue.length), 0));
1062
- return configRule.isBottom ? { rank: allValue[allValue.length - targetIndex] } : { rank: allValue[Math.max(targetIndex - 1, 0)] };
1118
+ const configRule = rule.rule, targetIndex = configRule.isPercent ? Math.floor(Math.max(Math.min(configRule.value, 100), 0) / 100 * allValue.length) : Math.floor(Math.max(Math.min(configRule.isBottom ? configRule.value - 1 : configRule.value, allValue.length), 0));
1119
+ return configRule.isBottom ? { rank: allValue[allValue.length - targetIndex - 1] } : { rank: allValue[Math.max(targetIndex - 1, 0)] };
1063
1120
  }
1064
1121
  case CFSubRuleType.formula: {
1065
1122
  const subRuleConfig = ruleConfig, lexerTreeBuilder = context.accessor.get(LexerTreeBuilder), formulaString = subRuleConfig.value, sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formulaString);
@@ -1226,41 +1283,6 @@ const dataBarCellCalculateUnit = {
1226
1283
  });
1227
1284
  }), computeResult;
1228
1285
  }, "handle")
1229
- }, emptyStyle = "", colorScaleCellCalculateUnit = {
1230
- type: CFRuleType.colorScale,
1231
- handle: /* @__PURE__ */ __name(async (rule, context) => {
1232
- var _a5;
1233
- const ruleConfig = rule.rule, conditionalFormattingFormulaService = context.accessor.get(ConditionalFormattingFormulaService), { worksheet } = context, matrix = new ObjectMatrix(), ranges = filterRange(rule.ranges, worksheet.getMaxRows() - 1, worksheet.getMaxColumns() - 1);
1234
- ranges.forEach((range) => {
1235
- Range.foreach(range, (row, col) => {
1236
- const cell2 = worksheet == null ? void 0 : worksheet.getCellRaw(row, col), v = cell2 && cell2.v;
1237
- if (!isNullable(v) && (cell2 == null ? void 0 : cell2.t) === CellValueType.NUMBER) {
1238
- const _value = Number(v);
1239
- !Number.isNaN(_value) && matrix.setValue(row, col, _value);
1240
- }
1241
- });
1242
- });
1243
- const computeResult = new ObjectMatrix();
1244
- ranges.forEach((range) => {
1245
- Range.foreach(range, (row, col) => {
1246
- computeResult.setValue(row, col, emptyStyle);
1247
- });
1248
- });
1249
- const _configList = [...ruleConfig.config].sort((a, b) => a.index - b.index).map((config) => ({
1250
- value: getValueByType(config.value, matrix, { ...context, cfId: rule.cfId }),
1251
- color: new ColorKit(config.color)
1252
- }));
1253
- if (_configList.some((item) => isObject(item.value) ? item.value.status !== FormulaResultStatus.SUCCESS : !1))
1254
- return (_a5 = conditionalFormattingFormulaService.getCache(context.unitId, context.subUnitId, rule.cfId)) != null ? _a5 : computeResult;
1255
- const colorList = _configList.map((item) => item.color).reduce((result, color, index) => (result.result.push({ color, value: result.sortValue[index] }), result), {
1256
- result: [],
1257
- sortValue: _configList.map((item) => item.value.result).sort((a, b) => a - b)
1258
- }).result;
1259
- return colorList.length <= 1 || matrix.forValue((row, col, value) => {
1260
- const color = getColorScaleFromValue(colorList, value);
1261
- color && computeResult.setValue(row, col, color);
1262
- }), computeResult;
1263
- }, "handle")
1264
1286
  }, iconSetCalculateUnit = {
1265
1287
  type: CFRuleType.iconSet,
1266
1288
  handle: /* @__PURE__ */ __name(async (rule, context) => {
@@ -1336,7 +1358,7 @@ let ConditionalFormattingService = (_a3 = class extends Disposable {
1336
1358
  __publicField(this, "ruleComputeStatus$", this._ruleComputeStatus$.asObservable());
1337
1359
  __publicField(this, "interceptorManager", new InterceptorManager({ beforeUpdateRuleResult }));
1338
1360
  __publicField(this, "_calculationUnitMap", /* @__PURE__ */ new Map());
1339
- this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel, this._injector = _injector, this._conditionalFormattingViewModel = _conditionalFormattingViewModel, this._univerInstanceService = _univerInstanceService, this._resourceManagerService = _resourceManagerService, this._sheetInterceptorService = _sheetInterceptorService, this._commandService = _commandService, this._initCellChange(), this._initCacheManager(), this._initRemoteCalculate(), this._initSnapshot(), this._initSheetChange(), this._registerCalculationUnit(dataBarCellCalculateUnit), this._registerCalculationUnit(colorScaleCellCalculateUnit), this._registerCalculationUnit(highlightCellCalculateUnit), this._registerCalculationUnit(iconSetCalculateUnit), this._calculateUnit$.pipe(bufferTime(16), filter((list) => !!list.length), map((list) => {
1361
+ this._conditionalFormattingRuleModel = _conditionalFormattingRuleModel, this._injector = _injector, this._conditionalFormattingViewModel = _conditionalFormattingViewModel, this._univerInstanceService = _univerInstanceService, this._resourceManagerService = _resourceManagerService, this._sheetInterceptorService = _sheetInterceptorService, this._commandService = _commandService, this._initCellChange(), this._initCacheManager(), this._initRemoteCalculate(), this._initSnapshot(), this._initSheetChange(), this._registerCalculationUnit(dataBarCellCalculateUnit), this._registerCalculationUnit(colorScaleCellCalculateUnit), this._registerCalculationUnit(highlightCellCalculateUnit), this._registerCalculationUnit(iconSetCalculateUnit), this._calculateUnit$.pipe(bufferTime(100), filter((list) => !!list.length), map((list) => {
1340
1362
  const createKey = /* @__PURE__ */ __name((config) => `${config.unitId}_${config.subUnitId}_${config.rule.cfId}`, "createKey");
1341
1363
  return list.reduce((a, b) => {
1342
1364
  const key = createKey(b);
@@ -1579,7 +1601,6 @@ let ConditionalFormattingService = (_a3 = class extends Disposable {
1579
1601
  }
1580
1602
  }, __name(_a3, "ConditionalFormattingService"), _a3);
1581
1603
  ConditionalFormattingService = __decorateClass$1([
1582
- OnLifecycle(LifecycleStages.Starting, ConditionalFormattingService),
1583
1604
  __decorateParam$1(0, Inject(ConditionalFormattingRuleModel)),
1584
1605
  __decorateParam$1(1, Inject(Injector)),
1585
1606
  __decorateParam$1(2, Inject(ConditionalFormattingViewModel)),
@@ -1591,29 +1612,7 @@ ConditionalFormattingService = __decorateClass$1([
1591
1612
  const getUnitId = /* @__PURE__ */ __name((u) => u.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId(), "getUnitId"), getSubUnitId = /* @__PURE__ */ __name((u) => {
1592
1613
  var _a5;
1593
1614
  return (_a5 = u.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : _a5.getSheetId();
1594
- }, "getSubUnitId"), SetConditionalRuleMutation = {
1595
- type: CommandType.MUTATION,
1596
- id: "sheet.mutation.set-conditional-rule",
1597
- handler(accessor, params) {
1598
- if (!params)
1599
- return !1;
1600
- const { unitId, subUnitId, rule } = params, cfId = params.cfId || params.rule.cfId;
1601
- return accessor.get(ConditionalFormattingRuleModel).setRule(unitId, subUnitId, rule, cfId), !0;
1602
- }
1603
- }, setConditionalRuleMutationUndoFactory = /* @__PURE__ */ __name((accessor, param) => {
1604
- const conditionalFormattingRuleModel = accessor.get(ConditionalFormattingRuleModel), { unitId, subUnitId } = param, cfId = param.cfId || param.rule.cfId, rule = conditionalFormattingRuleModel.getRule(unitId, subUnitId, cfId);
1605
- return rule ? [
1606
- {
1607
- id: SetConditionalRuleMutation.id,
1608
- params: {
1609
- unitId,
1610
- subUnitId,
1611
- cfId,
1612
- rule: Tools.deepClone(rule)
1613
- }
1614
- }
1615
- ] : [];
1616
- }, "setConditionalRuleMutationUndoFactory"), PLUGIN_CONFIG_KEY = "ssheets-conditional-formatting.config", defaultPluginConfig = {};
1615
+ }, "getSubUnitId");
1617
1616
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1618
1617
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1619
1618
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
@@ -1640,6 +1639,9 @@ let UniverSheetsConditionalFormattingPlugin = (_a4 = class extends Plugin {
1640
1639
  this._commandService.registerCommand(m);
1641
1640
  });
1642
1641
  }
1642
+ onStarting() {
1643
+ this._injector.get(ConditionalFormattingService);
1644
+ }
1643
1645
  }, __name(_a4, "UniverSheetsConditionalFormattingPlugin"), __publicField(_a4, "pluginName", SHEET_CONDITIONAL_FORMATTING_PLUGIN), __publicField(_a4, "type", UniverInstanceType.UNIVER_SHEET), _a4);
1644
1646
  UniverSheetsConditionalFormattingPlugin = __decorateClass([
1645
1647
  __decorateParam(1, Inject(Injector)),
@@ -1,5 +1,5 @@
1
- import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
2
1
  import { IUniverSheetsConditionalFormattingConfig } from './controllers/config.schema';
2
+ import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
3
  export declare class UniverSheetsConditionalFormattingPlugin extends Plugin {
4
4
  private readonly _config;
5
5
  readonly _injector: Injector;
@@ -8,4 +8,5 @@ export declare class UniverSheetsConditionalFormattingPlugin extends Plugin {
8
8
  static pluginName: string;
9
9
  static type: UniverInstanceType;
10
10
  constructor(_config: Partial<IUniverSheetsConditionalFormattingConfig> | undefined, _injector: Injector, _commandService: ICommandService, _configService: IConfigService);
11
+ onStarting(): void;
11
12
  }
@@ -1,7 +1,7 @@
1
1
  import { ObjectMatrix, Disposable, ICommandService, Injector, RefAlias } from '@univerjs/core';
2
2
  import { IActiveDirtyManagerService } from '@univerjs/engine-formula';
3
- import { ConditionalFormattingViewModel } from '../models/conditional-formatting-view-model';
4
3
  import { ConditionalFormattingRuleModel } from '../models/conditional-formatting-rule-model';
4
+ import { ConditionalFormattingViewModel } from '../models/conditional-formatting-view-model';
5
5
  type IFormulaItem = {
6
6
  formulaText: string;
7
7
  cfId: string;
@@ -1,9 +1,9 @@
1
+ import { IHighlightCell } from '../models/type';
2
+ import { IDataBarCellData, IIconSetCellData } from '../render/type';
1
3
  import { Disposable, ICommandService, Injector, InterceptorManager, IResourceManagerService, IUniverInstanceService, ObjectMatrix } from '@univerjs/core';
2
4
  import { SheetInterceptorService } from '@univerjs/sheets';
3
5
  import { ConditionalFormattingRuleModel } from '../models/conditional-formatting-rule-model';
4
6
  import { ConditionalFormattingViewModel } from '../models/conditional-formatting-view-model';
5
- import { IHighlightCell } from '../models/type';
6
- import { IDataBarCellData, IIconSetCellData } from '../render/type';
7
7
  type ComputeStatus = 'computing' | 'end' | 'error';
8
8
  export declare class ConditionalFormattingService extends Disposable {
9
9
  private _conditionalFormattingRuleModel;