Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(conditional-formatting): bugfix (#1838)
Gpound.liuc0b3dce0f713
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.tsindex 1962b11976..a049f3ddd3 100644--- a/packages/engine-formula/src/index.ts+++ b/packages/engine-formula/src/index.ts@@ -31,7 +31,7 @@ export type {IDirtyUnitSheetDefinedNameMap,} from './basics/common';export { isInDirtyRange } from './basics/dirty';-export { ErrorType } from './basics/error-type';+export { ErrorType, ERROR_TYPE_SET } from './basics/error-type';export { FunctionType, type IFunctionInfo, type IFunctionParam } from './basics/function';export { type IFunctionNames } from './basics/function';export { includeFormulaLexerToken, isFormulaLexerToken, normalizeSheetName } from './basics/match-token';diff --git a/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.ts b/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.tsindex 01a361cbb3..e2d63b2c03 100644--- a/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.ts+++ b/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.ts@@ -31,6 +31,7 @@ interface IAddUniqueValuesConditionalRuleParams {nativeColor: IDataBar['config']['nativeColor'];positiveColor: IDataBar['config']['positiveColor'];isGradient: IDataBar['config']['isGradient'];+ isShowValue: IDataBar['isShowValue'];}export const AddDataBarConditionalRuleCommand: ICommand<IAddUniqueValuesConditionalRuleParams> = {@@ -40,7 +41,7 @@ export const AddDataBarConditionalRuleCommand: ICommand<IAddUniqueValuesConditioif (!params) {return false;}- const { ranges, min, max, nativeColor, positiveColor, isGradient, stopIfTrue } = params;+ const { ranges, min, max, nativeColor, positiveColor, isGradient, stopIfTrue, isShowValue } = params;const conditionalFormattingRuleModel = accessor.get(ConditionalFormattingRuleModel);const univerInstanceService = accessor.get(IUniverInstanceService);const commandService = accessor.get(ICommandService);@@ -55,6 +56,7 @@ export const AddDataBarConditionalRuleCommand: ICommand<IAddUniqueValuesConditiostopIfTrue: !!stopIfTrue,rule: {type: CFRuleType.dataBar,+ isShowValue,config: {min, max, nativeColor, positiveColor, isGradient,},diff --git a/packages/sheets-conditional-formatting-ui/src/commands/operations/open-conditional-formatting-panel.ts b/packages/sheets-conditional-formatting-ui/src/commands/operations/open-conditional-formatting-panel.tsindex de29977d59..6ccaddb806 100644--- a/packages/sheets-conditional-formatting-ui/src/commands/operations/open-conditional-formatting-panel.ts+++ b/packages/sheets-conditional-formatting-ui/src/commands/operations/open-conditional-formatting-panel.ts@@ -100,6 +100,7 @@ export const OpenConditionalFormattingOperator: ICommand = {ranges,rule: {type: CFRuleType.dataBar,+ isShowValue: true,},} as unknown as IConditionFormattingRule<IDataBar>;conditionalFormattingMenuController.openPanel(rule);diff --git a/packages/sheets-conditional-formatting-ui/src/components/hook/useHighlightRange.ts b/packages/sheets-conditional-formatting-ui/src/components/hook/useHighlightRange.tsnew file mode 100644index 0000000000..55f9c7995b--- /dev/null+++ b/packages/sheets-conditional-formatting-ui/src/components/hook/useHighlightRange.ts@@ -0,0 +1,51 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { useEffect } from 'react';+import type { IRange } from '@univerjs/core';+import { useDependency } from '@wendellhu/redi/react-bindings';+import { IMarkSelectionService } from '@univerjs/sheets-ui';++export const useHighlightRange = (ranges: IRange[] = []) => {+ const markSelectionService = useDependency(IMarkSelectionService);+ useEffect(() => {+ const ids = ranges.map((range) => markSelectionService.addShape({+ range,+ style: {+ hasAutoFill: false,+ fill: 'rgba(73, 184, 17, 0.05)',+ strokeWidth: 1,+ stroke: '#49B811',+ widgets: {},+ },+ primary: {+ startColumn: range.startColumn,+ endColumn: range.endColumn,+ startRow: range.startRow,+ endRow: range.endRow,+ actualRow: range.startRow,+ actualColumn: range.startColumn,+ isMerged: false,+ isMergedMainCell: false,+ },+ }));+ return () => {+ ids.forEach((id) => {+ id && markSelectionService.removeShape(id);+ });+ };+ }, [ranges]);+};diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsxindex a770d8037c..f45d2156dc 100644--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx@@ -15,7 +15,7 @@*/import React, { useEffect, useMemo, useRef, useState } from 'react';-import { InputNumber, Radio, RadioGroup, Select } from '@univerjs/design';+import { Checkbox, InputNumber, Radio, RadioGroup, Select } from '@univerjs/design';import { useDependency } from '@wendellhu/redi/react-bindings';import { createInternalEditorID, IUniverInstanceService, LocaleService } from '@univerjs/core';import { TextEditor } from '@univerjs/ui';@@ -142,12 +142,21 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {return value.value === undefined ? defaultV : value.value;});+ const [isShowValue, isShowValueSet] = useState(() => {+ const defaultV = true;+ if (!rule) {+ return defaultV;+ }+ return rule.isShowValue === undefined ? defaultV : !!rule.isShowValue;+ });+const getResult = (option: { minValueType: CFValueType ;minValue: number | string;maxValueType: CFValueType ;maxValue: number | string;isGradient: string;positiveColor: string;+ isShowValue: boolean;nativeColor: string; }) => {const config: { min: IValueConfig;max: IValueConfig;@@ -160,16 +169,16 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {positiveColor: option.positiveColor,nativeColor: option.nativeColor,};- return { config, type: CFRuleType.dataBar };+ return { config, type: CFRuleType.dataBar, isShowValue: option.isShowValue };};useEffect(() => {const dispose = interceptorManager.intercept(interceptorManager.getInterceptPoints().submit, {handler() {- return getResult({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor });+ return getResult({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor, isShowValue });},});return dispose as () => void;- }, [isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor, interceptorManager]);+ }, [isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor, interceptorManager, isShowValue]);const _handleChange = (option: { minValueType: CFValueType ;minValue: number | string;@@ -177,6 +186,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {maxValue: number | string;isGradient: string;positiveColor: string;+ isShowValue: boolean;nativeColor: string; }) => {props.onChange(getResult(option));};@@ -184,11 +194,11 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {const handlePositiveColorChange = (color: string) => {positiveColorSet(color);- _handleChange({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor: color, nativeColor });+ _handleChange({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor: color, nativeColor, isShowValue });};const handleNativeColorChange = (color: string) => {nativeColorSet(color);- _handleChange({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor: color });+ _handleChange({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor: color, isShowValue });};const isShowInput = (type: string) => {@@ -201,19 +211,19 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {{localeService.t('sheet.cf.panel.styleRule')}</div><div className={`${styles.cfPreviewWrap}`}>- <Preview rule={getResult({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor }) as IConditionalFormattingRuleConfig} />+ <Preview rule={getResult({ isGradient, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor, isShowValue }) as IConditionalFormattingRuleConfig} /></div><div><div className={stylesBase.label}>{localeService.t('sheet.cf.panel.fillType')}</div>- <div className={`${stylesBase.mTSm} ${stylesBase.mLXxs} `}>+ <div className={`${stylesBase.mTSm} ${stylesBase.mLXxs} ${stylesBase.labelContainer} `}><RadioGroupvalue={isGradient}onChange={(v) => {isGradientSet(v as string);- _handleChange({ isGradient: v as string, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor });+ _handleChange({ isGradient: v as string, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor, isShowValue });}}><Radio value="0">@@ -223,6 +233,16 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {<span className={styles.text}>{localeService.t('sheet.cf.panel.gradient')}</span></Radio></RadioGroup>+ <div className={`${styles.utilItem} ${stylesBase.mLXl}`}>+ <Checkbox+ checked={!isShowValue}+ onChange={(v) => {+ isShowValueSet(!v);+ _handleChange({ isGradient: v as string, minValue, minValueType, maxValue, maxValueType, positiveColor, nativeColor, isShowValue: !v });+ }}+ />+ {localeService.t('sheet.cf.panel.onlyShowDataBar')}+ </div></div></div><div>@@ -255,7 +275,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {minValueTypeSet(v as CFValueType);const value = createDefaultValueByValueType(v as CFValueType, 10);minValueSet(value);- _handleChange({ isGradient, minValue: value, minValueType: v as CFValueType, maxValue, maxValueType, positiveColor, nativeColor });+ _handleChange({ isGradient, minValue: value, minValueType: v as CFValueType, maxValue, maxValueType, positiveColor, nativeColor, isShowValue });}}/>@@ -267,7 +287,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {value={minValue}onChange={(v) => {minValueSet(v || 0);- _handleChange({ isGradient, minValue: v || 0, minValueType, maxValue, maxValueType, positiveColor, nativeColor });+ _handleChange({ isGradient, minValue: v || 0, minValueType, maxValue, maxValueType, positiveColor, nativeColor, isShowValue });}}/></div>@@ -280,7 +300,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {maxValueTypeSet(v as CFValueType);const value = createDefaultValueByValueType(v as CFValueType, 90);maxValueSet(value);- _handleChange({ isGradient, minValue, minValueType, maxValue: value, maxValueType: v as CFValueType, positiveColor, nativeColor });+ _handleChange({ isGradient, minValue, minValueType, maxValue: value, maxValueType: v as CFValueType, positiveColor, nativeColor, isShowValue });}}/><InputText@@ -291,7 +311,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {value={maxValue}onChange={(v) => {maxValueSet(v || 0);- _handleChange({ isGradient, minValue, minValueType, maxValue: v || 0, maxValueType, positiveColor, nativeColor });+ _handleChange({ isGradient, minValue, minValueType, maxValue: v || 0, maxValueType, positiveColor, nativeColor, isShowValue });}}/></div>diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/highlightCell.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/highlightCell.tsxindex 16bab70e53..2ef6e73b50 100644--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/highlightCell.tsx+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/highlightCell.tsx@@ -145,7 +145,10 @@ const getOperatorOptions = (type: CFSubRuleType.duplicateValues | CFSubRuleType.createOptionItem(CFTextOperator.equal, localeService),createOptionItem(CFTextOperator.notEqual, localeService),createOptionItem(CFTextOperator.containsBlanks, localeService),- createOptionItem(CFTextOperator.notContainsBlanks, localeService)];+ createOptionItem(CFTextOperator.notContainsBlanks, localeService),+ createOptionItem(CFTextOperator.containsErrors, localeService),+ createOptionItem(CFTextOperator.notContainsErrors, localeService),+ ];}case CFSubRuleType.number:{return [@@ -203,7 +206,8 @@ export const HighlightCellStyleEditor = (props: IStyleEditorProps<any, ITextHigh}, {value: CFSubRuleType.uniqueValues,label: localeService.t('sheet.cf.subRuleType.uniqueValues'),- }];+ },+ ];const operatorOptions = useMemo(() => getOperatorOptions(subType, localeService), [subType]);const [operator, operatorSet] = useState<IResult['operator'] | undefined>(() => {diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.module.less b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.module.lessindex f6bac9be76..a6488b2231 100644--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.module.less+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.module.less@@ -17,17 +17,20 @@justify-content: flex-end;margin-bottom: var(--margin-base);}++ .util-item {+ display: flex;+ justify-content: flex-start;+ align-items: center;+ font-size: var(--font-size-xxs);+ }+.icon-set {.render-config {display: flex;align-items: center;font-size: var(--font-size-xxs);justify-content: flex-start;- .util-item {- display: flex;- justify-content: flex-start;- align-items: center;- }}.flex {display: flex;diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsxindex d656a1d4d6..e51ad35aba 100644--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx@@ -23,7 +23,7 @@ import { Button, Select } from '@univerjs/design';import { RangeSelector } from '@univerjs/ui';import type { IRemoveSheetMutationParams } from '@univerjs/sheets';-import { RemoveSheetMutation, SelectionManagerService, SetWorksheetActiveOperation } from '@univerjs/sheets';+import { RemoveSheetMutation, SelectionManagerService, setEndForRange, SetWorksheetActiveOperation } from '@univerjs/sheets';import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';import { CFRuleType, CFSubRuleType, ConditionalFormattingRuleModel, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';import type { IAddCfCommandParams } from '../../../commands/commands/add-cf.command';@@ -182,9 +182,10 @@ export const RuleEdit = (props: IRuleEditProps) => {const handleSubmit = () => {const beforeSubmitResult = interceptorManager.fetchThroughInterceptors(interceptorManager.getInterceptPoints().beforeSubmit)(true, null);const getRanges = () => {- const ranges = rangeResult.current;- const isError = ranges.some((range) => Number.isNaN(range.startRow) || Number.isNaN(range.startColumn));- return isError ? [] : ranges;+ const worksheet = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet();+ const ranges = rangeResult.current.map((range) => setEndForRange(range, worksheet.getRowCount(), worksheet.getColumnCount()));+ const result = ranges.filter((range) => !(Number.isNaN(range.startRow) || Number.isNaN(range.startColumn)));+ return result;};if (beforeSubmitResult) {diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.module.less b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.module.lessindex 392cd54a4e..ef00837ba8 100644--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.module.less+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.module.less@@ -7,7 +7,7 @@align-items: center;.select {color: rgb(var(--text-color));- width: 126px;+ width: 138px;.select-selector {border: none;padding: 0;diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.tsxindex 97df5b8c85..4a5ac59f05 100644--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.tsx+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-list/index.tsx@@ -18,6 +18,7 @@ import React, { useEffect, useRef, useState } from 'react';import { Select, Tooltip } from '@univerjs/design';import { useDependency } from '@wendellhu/redi/react-bindings';+import type { IRange } from '@univerjs/core';import { ICommandService, IUniverInstanceService, LocaleService, Rectangle } from '@univerjs/core';import { SelectionManagerService, SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';import { serializeRange } from '@univerjs/engine-formula';@@ -35,6 +36,7 @@ import 'react-resizable/css/styles.css';import { Preview } from '../../preview';import { ConditionalFormattingI18nController } from '../../../controllers/cf.i18n.controller';import { ClearWorksheetCfCommand } from '../../../commands/commands/clear-worksheet-cf.command';+import { useHighlightRange } from '../../hook/useHighlightRange';import styles from './index.module.less';@@ -115,15 +117,19 @@ export const RuleList = (props: IRuleListProps) => {const unitId = workbook.getUnitId();const worksheet = workbook.getActiveSheet();const subUnitId = worksheet.getSheetId();++ const [currentRuleRanges, currentRuleRangesSet] = useState<IRange[]>([]);const [selectValue, selectValueSet] = useState('2');const [fetchRuleListId, fetchRuleListIdSet] = useState(0);const [draggingId, draggingIdSet] = useState<number>(-1);const [layoutWidth, layoutWidthSet] = useState(defaultWidth);const layoutContainerRef = useRef<HTMLDivElement>(null);+const selectOption = [{ label: localeService.t('sheet.cf.panel.workSheet'), value: '2' },{ label: localeService.t('sheet.cf.panel.selectedRange'), value: '1' },];+const getRuleList = () => {const ruleList = conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId);if (!ruleList || !ruleList.length) {@@ -146,6 +152,8 @@ export const RuleList = (props: IRuleListProps) => {};const [ruleList, ruleListSet] = useState(getRuleList);+ useHighlightRange(currentRuleRanges);+useEffect(() => {const disposable = commandService.onCommandExecuted((commandInfo) => {if (commandInfo.id === SetWorksheetActiveOperation.id) {@@ -320,7 +328,14 @@ export const RuleList = (props: IRuleListProps) => {{ruleList.map((rule, index) => {return (<div key={`${rule.cfId}`}>- <div className={`${styles.ruleItem} ${draggingId === index ? styles.active : ''}`} onClick={() => onClick(rule)}>+ <div+ onMouseMove={() => {+ rule.ranges !== currentRuleRanges && currentRuleRangesSet(rule.ranges);+ }}+ onMouseLeave={() => currentRuleRangesSet([])}+ onClick={() => onClick(rule)}+ className={`${styles.ruleItem} ${draggingId === index ? styles.active : ''}`}+ ><divclassName={`${styles.draggableHandle} draggableHandle`}onClick={(e) => e.stopPropagation()}diff --git a/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.ts b/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.tsindex 90ab82d357..83cbdabfe0 100644--- a/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.ts+++ b/packages/sheets-conditional-formatting-ui/src/controllers/cf.render.controller.ts@@ -106,20 +106,18 @@ export class RenderController extends Disposable {if (result.style) {Object.assign(s, result.style);}+ if (!cloneCell.fontRenderExtension) {+ cloneCell.fontRenderExtension = {};+ if (!result.isShowValue) {+ cloneCell.fontRenderExtension.isSkip = true;+ }+ }if (result.dataBar) {cloneCell.dataBar = result.dataBar;}if (result.iconSet) {cloneCell.iconSet = result.iconSet;- if (!cloneCell.fontRenderExtension) {- cloneCell.fontRenderExtension = {};- }-cloneCell.fontRenderExtension.leftOffset = DEFAULT_PADDING + DEFAULT_WIDTH;-- if (!result.iconSet.isShowValue) {- cloneCell.fontRenderExtension.isSkip = true;- }}return next(cloneCell);diff --git a/packages/sheets-conditional-formatting-ui/src/locale/en-US.ts b/packages/sheets-conditional-formatting-ui/src/locale/en-US.tsindex e5bda71d1b..c042c065b7 100644--- a/packages/sheets-conditional-formatting-ui/src/locale/en-US.ts+++ b/packages/sheets-conditional-formatting-ui/src/locale/en-US.ts@@ -77,6 +77,7 @@ const locale: typeof zhCN = {workSheet: 'Entire Sheet',selectedRange: 'Selected Range',managerRuleSelect: 'Manage {0} Rules',+ onlyShowDataBar: 'Only Show Data Bars',},preview: {describe: {diff --git a/packages/sheets-conditional-formatting-ui/src/locale/zh-CN.ts b/packages/sheets-conditional-formatting-ui/src/locale/zh-CN.tsindex aa5d66675f..9d8d525ab7 100644--- a/packages/sheets-conditional-formatting-ui/src/locale/zh-CN.ts+++ b/packages/sheets-conditional-formatting-ui/src/locale/zh-CN.ts@@ -75,6 +75,7 @@ const locale = {workSheet: '整张工作表',selectedRange: '所选单元格',managerRuleSelect: '管理 {0} 的规则',+ onlyShowDataBar: '仅显示数据条',},preview: {describe: {diff --git a/packages/sheets-conditional-formatting/src/models/icon-map.ts b/packages/sheets-conditional-formatting/src/models/icon-map.tsindex e85ce07c51..a0dc025888 100644--- a/packages/sheets-conditional-formatting/src/models/icon-map.ts+++ b/packages/sheets-conditional-formatting/src/models/icon-map.ts@@ -18,14 +18,18 @@ import ICON_MAP from '../assets/icon-map.json';export type IIconItem = string;-export const iconGroup: { title: string;group: { name: string;list: string[] }[] }[] = [+export const iconGroup: { title: string; group: { name: string; list: string[] }[] }[] = [{title: 'sheet.cf.iconSet.direction',group: [{ name: '3Arrows', list: [ICON_MAP.arrow['up-green'], ICON_MAP.arrow['right-gold'], ICON_MAP.arrow['down-red']] },- { name: '_3Shape', list: [ICON_MAP.shape.up, ICON_MAP.shape.cross, ICON_MAP.shape.down] },+ { name: '3ArrowsGray', list: [ICON_MAP.arrow['up-gray'], ICON_MAP.arrow['right-gray'], ICON_MAP.arrow['down-gray']] },{ name: '4Arrows', list: [ICON_MAP.arrow['up-green'], ICON_MAP.arrow['rightAndUp-gold'], ICON_MAP.arrow['rightAndDown-gold'], ICON_MAP.arrow['down-red']] },+ { name: '4ArrowsGray', list: [ICON_MAP.arrow['down-gray'], ICON_MAP.arrow['rightAndDown-gray'], ICON_MAP.arrow['rightAndUp-gray'], ICON_MAP.arrow['up-gray']] },{ name: '5Arrows', list: [ICON_MAP.arrow['up-green'], ICON_MAP.arrow['rightAndUp-gold'], ICON_MAP.arrow['right-gold'], ICON_MAP.arrow['rightAndDown-gold'], ICON_MAP.arrow['down-red']] },+ { name: '5ArrowsGray', list: [ICON_MAP.arrow['down-gray'], ICON_MAP.arrow['rightAndDown-gray'], ICON_MAP.arrow['right-gray'], ICON_MAP.arrow['rightAndUp-gray'], ICON_MAP.arrow['up-gray']] },+ { name: '3Triangles', list: [ICON_MAP.shape.down, ICON_MAP.shape.cross, ICON_MAP.shape.up] },+],},@@ -38,13 +42,13 @@ export const iconGroup: { title: string;group: { name: string;list: string[] }[]{name: '3Signs', list: [ICON_MAP.shape['roundness-greed'], ICON_MAP.shape['triangle-gold'], ICON_MAP.shape['rhomboid-red']],},+ { name: '3TrafficLights2', list: [ICON_MAP.shape['indicate-red'], ICON_MAP.shape['indicate-gold'], ICON_MAP.shape['indicate-greed']] },{name: '4RedToBlack', list: [ICON_MAP.shape['roundness-red'], ICON_MAP.shape['roundness-pink'], ICON_MAP.shape['roundness-gray'], ICON_MAP.shape['roundness-black']],},{name: '4TrafficLights', list: [ICON_MAP.shape['roundness-greed'], ICON_MAP.shape['roundness-gold'], ICON_MAP.shape['roundness-red'], ICON_MAP.shape['roundness-black']],},- { name: '_3Indicate', list: [ICON_MAP.shape['indicate-greed'], ICON_MAP.shape['indicate-gold'], ICON_MAP.shape['indicate-red']] },],},{@@ -57,7 +61,7 @@ export const iconGroup: { title: string;group: { name: string;list: string[] }[]name: '3Symbols2', list: [ICON_MAP.feedback2.correct2, ICON_MAP.feedback2.warn2, ICON_MAP.feedback2.mistake2],},{- name: '3Flags', list: [ICON_MAP.flag['flag-green'], ICON_MAP.flag['flag-gold'], ICON_MAP.flag['flag-red']],+ name: '3Flags', list: [ICON_MAP.flag['flag-red'], ICON_MAP.flag['flag-gold'], ICON_MAP.flag['flag-green']],},],@@ -66,19 +70,22 @@ export const iconGroup: { title: string;group: { name: string;list: string[] }[]title: 'sheet.cf.iconSet.rank',group: [{- name: '3Stars', list: [ICON_MAP.star.starEmpty, ICON_MAP.star.starIncomplete, ICON_MAP.star.starFull],+ name: '4Rating', list: [ICON_MAP.signal.signal100, ICON_MAP.signal.signal75, ICON_MAP.signal.signal50, ICON_MAP.signal.signal25],+ },+ {+ name: '5Rating', list: [ICON_MAP.signal.signal100, ICON_MAP.signal.signal75, ICON_MAP.signal.signal50, ICON_MAP.signal.signal25, ICON_MAP.signal.signal0],},{name: '5Quarters', list: [ICON_MAP.progress.progress0, ICON_MAP.progress.progress25, ICON_MAP.progress.progress50, ICON_MAP.progress.progress75, ICON_MAP.progress.progress100],},{- name: '5Rating', list: [ICON_MAP.feeling.guffaw, ICON_MAP.feeling.smile, ICON_MAP.feeling.noninductive, ICON_MAP.feeling.dissatisfied, ICON_MAP.feeling.impatient],+ name: '_5Felling', list: [ICON_MAP.feeling.guffaw, ICON_MAP.feeling.smile, ICON_MAP.feeling.noninductive, ICON_MAP.feeling.dissatisfied, ICON_MAP.feeling.impatient],},{- name: '_5Rating2', list: [ICON_MAP.signal.signal0, ICON_MAP.signal.signal25, ICON_MAP.signal.signal50, ICON_MAP.signal.signal75, ICON_MAP.signal.signal100],+ name: '5Boxes', list: [ICON_MAP.cell['cell-0'], ICON_MAP.cell['cell-25'], ICON_MAP.cell['cell-50'], ICON_MAP.cell['cell-75'], ICON_MAP.cell['cell-100']],},{- name: '_5Rating3', list: [ICON_MAP.cell['cell-0'], ICON_MAP.cell['cell-25'], ICON_MAP.cell['cell-50'], ICON_MAP.cell['cell-75'], ICON_MAP.cell['cell-100']],+ name: '3Stars', list: [ICON_MAP.star.starFull, ICON_MAP.star.starIncomplete, ICON_MAP.star.starEmpty],},],},diff --git a/packages/sheets-conditional-formatting/src/models/type.ts b/packages/sheets-conditional-formatting/src/models/type.tsindex 1762ad868f..f03a3e62ac 100644--- a/packages/sheets-conditional-formatting/src/models/type.ts+++ b/packages/sheets-conditional-formatting/src/models/type.ts@@ -78,6 +78,7 @@ export interface IAverageHighlightCell extends IHighlightCell {export interface IDataBar extends IBaseCfRule {type: CFRuleType.dataBar;+ isShowValue: boolean;config: {min: IValueConfig;max: IValueConfig;diff --git a/packages/sheets-conditional-formatting/src/render/type.ts b/packages/sheets-conditional-formatting/src/render/type.tsindex 9e72f22be3..b955f0cf0b 100644--- a/packages/sheets-conditional-formatting/src/render/type.ts+++ b/packages/sheets-conditional-formatting/src/render/type.ts@@ -22,6 +22,8 @@ export interface IDataBarRenderParams {value: number; // -100 - 100.startPoint: number; //0-100isGradient: boolean;+ isShowValue: boolean;+}export interface IDataBarCellData extends ICellData {dataBar?: IDataBarRenderParams;diff --git a/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.ts b/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.tsindex 5fe3205234..42d61a89b7 100644--- a/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.ts+++ b/packages/sheets-conditional-formatting/src/services/__test__/cf.service.spec.ts@@ -721,6 +721,7 @@ describe('Test conditional formatting service', () => {stopIfTrue: false,rule: {type: CFRuleType.dataBar,+ isShowValue: true,config: {min: { value: 2, type: CFValueType.num },max: { value: 5, type: CFValueType.num },@@ -747,7 +748,9 @@ describe('Test conditional formatting service', () => {startPoint: 0,value: 0,isGradient: true,+ isShowValue: true,},+ isShowValue: true,});expect(three).toEqual({dataBar: {@@ -755,7 +758,10 @@ describe('Test conditional formatting service', () => {startPoint: 0,value: 33.333333333333336,isGradient: true,+ isShowValue: true,},+ isShowValue: true,+});expect(four).toEqual({@@ -764,7 +770,10 @@ describe('Test conditional formatting service', () => {startPoint: 0,value: 66.66666666666667,isGradient: true,+ isShowValue: true,},+ isShowValue: true,+});expect(five).toEqual({dataBar: {@@ -772,7 +781,9 @@ describe('Test conditional formatting service', () => {startPoint: 0,value: 100,isGradient: true,+ isShowValue: true,},+ isShowValue: true,});});});diff --git a/packages/sheets-conditional-formatting/src/services/calculate-unit/data-bar.ts b/packages/sheets-conditional-formatting/src/services/calculate-unit/data-bar.tsindex 22af5c15e8..977e1894b9 100644--- a/packages/sheets-conditional-formatting/src/services/calculate-unit/data-bar.ts+++ b/packages/sheets-conditional-formatting/src/services/calculate-unit/data-bar.ts@@ -30,7 +30,7 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {const conditionalFormattingFormulaService = context.accessor.get(ConditionalFormattingFormulaService);const { worksheet } = context;- const matrix = new ObjectMatrix< number>();+ const matrix = new ObjectMatrix<number>();rule.ranges.forEach((range) => {Range.foreach(range, (row, col) => {@@ -43,7 +43,7 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {});});- const computeResult = new ObjectMatrix<IDataBarRenderParams >();+ const computeResult = new ObjectMatrix<IDataBarRenderParams>();rule.ranges.forEach((range) => {Range.foreach(range, (row, col) => {computeResult.setValue(row, col, EMPTY_STYLE as IDataBarRenderParams);@@ -55,8 +55,8 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {let min = 0;let max = 0;- // If the formula triggers the calculation, wait for the result,- // and use the previous style cache until the result comes out。+ // If the formula triggers the calculation, wait for the result,+ // and use the previous style cache until the result comes out。if (_min.status === FormulaResultStatus.WAIT) {return conditionalFormattingFormulaService.getCache(context.unitId, context.subUnitId, rule.cfId) || computeResult;} else if (_min.status === FormulaResultStatus.SUCCESS) {@@ -75,6 +75,7 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {}const isGradient = ruleConfig.config.isGradient;+ const isShowValue = ruleConfig.isShowValue;const getSafeValue = (v: number) => Math.max(Math.min(100, v), 0);@@ -88,7 +89,7 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {return;}const v = getSafeValue((max - value) / length * 100);- computeResult.setValue(row, col, { color: ruleConfig.config.nativeColor, startPoint, value: -v, isGradient });+ computeResult.setValue(row, col, { color: ruleConfig.config.nativeColor, startPoint, value: -v, isGradient, isShowValue });});} else if (min < 0 && max > 0) {const length = Math.abs(max) + Math.abs(min);@@ -99,10 +100,10 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {}if (value > 0) {const v = getSafeValue(Math.min(value / max, 1) * 100);- computeResult.setValue(row, col, { color: ruleConfig.config.positiveColor, startPoint, value: v, isGradient });+ computeResult.setValue(row, col, { color: ruleConfig.config.positiveColor, startPoint, value: v, isGradient, isShowValue });} else {const v = getSafeValue(Math.min(Math.abs(value) / Math.abs(min), 1) * 100);- computeResult.setValue(row, col, { color: ruleConfig.config.nativeColor, startPoint, value: -v, isGradient });+ computeResult.setValue(row, col, { color: ruleConfig.config.nativeColor, startPoint, value: -v, isGradient, isShowValue });}});} else if (min >= 0 && max > 0) {@@ -113,7 +114,7 @@ export const dataBarCellCalculateUnit: ICalculateUnit = {return;}const v = getSafeValue((1 - (max - value) / length) * 100);- computeResult.setValue(row, col, { color: ruleConfig.config.positiveColor, startPoint, value: v, isGradient });+ computeResult.setValue(row, col, { color: ruleConfig.config.positiveColor, startPoint, value: v, isGradient, isShowValue });});}return computeResult;diff --git a/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.ts b/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.tsindex 33dc1e85b1..2e58047f09 100644--- a/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.ts+++ b/packages/sheets-conditional-formatting/src/services/calculate-unit/highlight-cell.ts@@ -17,7 +17,7 @@import type { IStyleBase } from '@univerjs/core';import { CellValueType, ObjectMatrix, Range, Rectangle, Tools } from '@univerjs/core';import dayjs from 'dayjs';-import { deserializeRangeWithSheet, generateStringWithSequence, LexerTreeBuilder, sequenceNodeType, serializeRange } from '@univerjs/engine-formula';+import { deserializeRangeWithSheet, ERROR_TYPE_SET, generateStringWithSequence, LexerTreeBuilder, sequenceNodeType, serializeRange } from '@univerjs/engine-formula';import { CFNumberOperator, CFRuleType, CFSubRuleType, CFTextOperator, CFTimePeriodOperator } from '../../base/const';import type { IAverageHighlightCell, IConditionFormattingRule, IFormulaHighlightCell, IHighlightCell, INumberHighlightCell, IRankHighlightCell, ITextHighlightCell, ITimePeriodHighlightCell } from '../../models/type';import { ConditionalFormattingFormulaService, FormulaResultStatus } from '../conditional-formatting-formula.service';@@ -132,11 +132,10 @@ export const highlightCellCalculateUnit: ICalculateUnit = {return !/^\s*$/.test(v);}case CFTextOperator.containsErrors:{- // wait do do.- return false;+ return (ERROR_TYPE_SET as Set<unknown>).has(v);}case CFTextOperator.notContainsErrors:{- return false;+ return !(ERROR_TYPE_SET as Set<unknown>).has(v);}case CFTextOperator.containsText:{return v.indexOf(condition) > -1;diff --git a/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.ts b/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.tsindex f11086f48c..b598a1cd90 100644--- a/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.ts+++ b/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.ts@@ -39,13 +39,13 @@ type ComputeStatus = 'computing' | 'end' | 'error';interface IComputeCache { status: ComputeStatus };-const beforeUpdateRuleResult = createInterceptorKey< { subUnitId: string; unitId: string; cfId: string }>('conditional-formatting-before-update-rule-result');+const beforeUpdateRuleResult = createInterceptorKey<{ subUnitId: string; unitId: string; cfId: string }>('conditional-formatting-before-update-rule-result');@OnLifecycle(LifecycleStages.Starting, ConditionalFormattingService)export class ConditionalFormattingService extends Disposable {// <unitId,<subUnitId,<cfId,IComputeCache>>>private _ruleCacheMap: Map<string, Map<string, Map<string, IComputeCache>>> = new Map();- private _ruleComputeStatus$: Subject<{ status: ComputeStatus;result?: ObjectMatrix<any>;unitId: string; subUnitId: string; cfId: string }> = new Subject();+ private _ruleComputeStatus$: Subject<{ status: ComputeStatus; result?: ObjectMatrix<any>; unitId: string; subUnitId: string; cfId: string }> = new Subject();public ruleComputeStatus$ = this._ruleComputeStatus$.asObservable();public interceptorManager = new InterceptorManager({ beforeUpdateRuleResult });@@ -100,15 +100,17 @@ export class ConditionalFormattingService extends Disposable {const ruleCache = ruleCacheItem?.ruleCache as IDataBarRenderParams;if (ruleCache && ruleCache !== EMPTY_STYLE) {pre.dataBar = ruleCache;+ pre.isShowValue = ruleCache.isShowValue;}} else if (type === CFRuleType.iconSet) {const ruleCache = ruleCacheItem?.ruleCache as IIconSetRenderParams;if (ruleCache && ruleCache !== EMPTY_STYLE) {pre.iconSet = ruleCache;+ pre.isShowValue = ruleCache.isShowValue;}}return pre;- }, {} as { style?: IHighlightCell['style'] } & IDataBarCellData & IIconSetCellData);+ }, {} as { style?: IHighlightCell['style'] } & IDataBarCellData & IIconSetCellData & { isShowValue: boolean });return result;}return null;@@ -261,7 +263,7 @@ export class ConditionalFormattingService extends Disposable {};switch (commandInfo.id) {- case SetRangeValuesMutation.id:{+ case SetRangeValuesMutation.id: {const params = commandInfo.params as ISetRangeValuesMutationParams;const { subUnitId, unitId, cellValue } = params;const cellMatrix: [number, number][] = [];@@ -280,7 +282,7 @@ export class ConditionalFormattingService extends Disposable {break;}case InsertColMutation.id:- case RemoveColMutation.id:{+ case RemoveColMutation.id: {const { range, unitId, subUnitId } = commandInfo.params as IInsertColMutationParams;const allRules = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId);const effectRange: IRange = { ...range, endColumn: Number.MAX_SAFE_INTEGER };@@ -294,7 +296,7 @@ export class ConditionalFormattingService extends Disposable {break;}case RemoveRowMutation.id:- case InsertRowMutation.id:{+ case InsertRowMutation.id: {const { range, unitId, subUnitId } = commandInfo.params as IRemoveRowsMutationParams;const allRules = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId);const effectRange: IRange = { ...range, endRow: Number.MAX_SAFE_INTEGER };@@ -307,13 +309,15 @@ export class ConditionalFormattingService extends Disposable {}break;}- case MoveRowsMutation.id:{+ case MoveRowsMutation.id: {const { sourceRange, targetRange, unitId, subUnitId } = commandInfo.params as IMoveRowsMutationParams;const allRules = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId);- const effectRange: IRange = { startRow: Math.min(sourceRange.startRow, targetRange.startRow),- endRow: Number.MAX_SAFE_INTEGER,- startColumn: 0,- endColumn: Number.MAX_SAFE_INTEGER };+ const effectRange: IRange = {+ startRow: Math.min(sourceRange.startRow, targetRange.startRow),+ endRow: Number.MAX_SAFE_INTEGER,+ startColumn: 0,+ endColumn: Number.MAX_SAFE_INTEGER,+ };if (allRules) {const effectRule = allRules.filter((rule) => rule.ranges.some((ruleRange) => Rectangle.intersects(ruleRange, effectRange)));effectRule.forEach((rule) => {@@ -323,13 +327,15 @@ export class ConditionalFormattingService extends Disposable {}break;}- case MoveColsMutation.id:{+ case MoveColsMutation.id: {const { sourceRange, targetRange, unitId, subUnitId } = commandInfo.params as IMoveColumnsMutationParams;const allRules = this._conditionalFormattingRuleModel.getSubunitRules(unitId, subUnitId);- const effectRange: IRange = { startRow: 0,- endRow: Number.MAX_SAFE_INTEGER,- startColumn: Math.min(sourceRange.startColumn, targetRange.startColumn),- endColumn: Number.MAX_SAFE_INTEGER };+ const effectRange: IRange = {+ startRow: 0,+ endRow: Number.MAX_SAFE_INTEGER,+ startColumn: Math.min(sourceRange.startColumn, targetRange.startColumn),+ endColumn: Number.MAX_SAFE_INTEGER,+ };if (allRules) {const effectRule = allRules.filter((rule) => rule.ranges.some((ruleRange) => Rectangle.intersects(ruleRange, effectRange)));effectRule.forEach((rule) => {@@ -339,7 +345,7 @@ export class ConditionalFormattingService extends Disposable {}break;}- case MoveRangeMutation.id:{+ case MoveRangeMutation.id: {const { unitId, to, from } = commandInfo.params as IMoveRangeMutationParams;const handleSubUnit = (value: IMoveRangeMutationParams['from']) => {const cellMatrix: [number, number][] = [];