From e0c557229551162f0a7c701df4930750e8a44eac Mon Sep 17 00:00:00 2001 From: zw Date: Fri, 13 Sep 2024 02:04:50 +0800 Subject: [PATCH 1/3] feat: update --- .../src/validators/base-data-validator.ts | 4 +- .../src/controllers/dv-render.controller.ts | 61 ++++--------------- .../src/validators/checkbox-validator.ts | 8 ++- .../src/validators/list-validator.ts | 34 ++++++++--- 4 files changed, 48 insertions(+), 59 deletions(-) diff --git a/packages/data-validation/src/validators/base-data-validator.ts b/packages/data-validation/src/validators/base-data-validator.ts index 1f68e6f81c7..426a5fe7548 100644 --- a/packages/data-validation/src/validators/base-data-validator.ts +++ b/packages/data-validation/src/validators/base-data-validator.ts @@ -15,7 +15,7 @@ */ import { DataValidationOperator, Inject, Injector, LocaleService, Tools } from '@univerjs/core'; -import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable, Workbook, Worksheet } from '@univerjs/core'; +import type { CellValue, IDataValidationRule, IDataValidationRuleBase, IStyleData, Nullable, Workbook, Worksheet } from '@univerjs/core'; import type { CellValueType } from '@univerjs/protocol'; import { OperatorErrorTitleMap, OperatorTitleMap } from '../types/const/operator-text-map'; import type { IBaseDataValidationWidget } from './base-widget'; @@ -111,6 +111,8 @@ export abstract class BaseDataValidator { return `${errorMsg}`; } + getExtraStyle(rule: IDataValidationRuleBase, value: Nullable, ctx: { style: IStyleData }): Nullable {} + getRuleFinalError(rule: IDataValidationRule) { if (rule.showErrorMessage && rule.error) { return rule.error; diff --git a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts index 04735d4c7fa..5e74489dfd5 100644 --- a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts +++ b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts @@ -164,26 +164,16 @@ export class SheetsDataValidationRenderController extends RxDisposable { { // must be after numfmt priority: InterceptCellContentPriority.DATA_VALIDATION, - // eslint-disable-next-line max-lines-per-function, complexity + // eslint-disable-next-line complexity handler: (cell, pos, next) => { const { row, col, unitId, subUnitId, workbook, worksheet } = pos; - - const skeleton = this._renderManagerService.getRenderById(unitId) - ?.with(SheetSkeletonManagerService) - .getWorksheetSkeleton(subUnitId) - ?.skeleton; - if (!skeleton) { - return next(cell); - } - - const styleMap = pos.workbook.getStyles(); + const styleMap = workbook.getStyles(); const defaultStyle = (typeof cell?.s === 'string' ? styleMap.get(cell?.s) : cell?.s) || {}; const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col); if (!ruleId) { return next(cell); } const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId); - if (!rule) { return next(cell); } @@ -191,46 +181,10 @@ export class SheetsDataValidationRenderController extends RxDisposable { const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type); const cellOrigin = worksheet.getCellRaw(row, col); const cellValue = getCellValueOrigin(cellOrigin); - - let extra: ICellDataForSheetInterceptor = {}; - if (rule.type === DataValidationType.LIST || rule.type === DataValidationType.LIST_MULTIPLE) { - extra = { - interceptorStyle: { - ...cell?.interceptorStyle, - tb: (defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) ?? WrapStrategy.WRAP, - }, - }; - } - - if (rule.type === DataValidationType.CHECKBOX) { - extra = { - interceptorStyle: { - ...cell?.interceptorStyle, - tb: WrapStrategy.CLIP, - }, - }; - } - - if (rule.type === DataValidationType.LIST && (rule.renderMode === DataValidationRenderMode.ARROW || rule.renderMode === DataValidationRenderMode.TEXT)) { - const colorMap = (validator as ListValidator).getListWithColorMap(rule); - const valueStr = `${getCellValueOrigin(cellOrigin) ?? ''}`; - const color = colorMap[valueStr]; - if (color) { - extra = { - ...extra, - interceptorStyle: { - ...extra.interceptorStyle, - bg: { - rgb: color, - }, - }, - }; - } - } + const valueStr = `${getCellValueOrigin(cellOrigin) ?? ''}`; return next({ ...cell, - ...extra, dataValidation: { ruleId, validStatus, @@ -251,9 +205,16 @@ export class SheetsDataValidationRenderController extends RxDisposable { }, interceptorStyle: { ...cell?.interceptorStyle, - ...extra.interceptorStyle, + ...validator?.getExtraStyle(rule, valueStr, { style: defaultStyle }), }, interceptorAutoHeight: () => { + const skeleton = this._renderManagerService.getRenderById(unitId) + ?.with(SheetSkeletonManagerService) + .getWorksheetSkeleton(subUnitId) + ?.skeleton; + if (!skeleton) { + return undefined; + } const mergeCell = skeleton.mergeData.find((range) => { const { startColumn, startRow, endColumn, endRow } = range; return row >= startRow && col >= startColumn && row <= endRow && col <= endColumn; diff --git a/packages/sheets-data-validation/src/validators/checkbox-validator.ts b/packages/sheets-data-validation/src/validators/checkbox-validator.ts index 1107cdc9249..24f6c72d2af 100644 --- a/packages/sheets-data-validation/src/validators/checkbox-validator.ts +++ b/packages/sheets-data-validation/src/validators/checkbox-validator.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { DataValidationType, isFormulaString, Tools } from '@univerjs/core'; +import { DataValidationType, isFormulaString, Tools, WrapStrategy } from '@univerjs/core'; import { BaseDataValidator } from '@univerjs/data-validation'; import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase, ISheetDataValidationRule, LocaleService, Nullable } from '@univerjs/core'; import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation'; @@ -111,6 +111,12 @@ export class CheckboxValidator extends BaseDataValidator { }; } + override getExtraStyle(rule: IDataValidationRule, value: Nullable, ctx) { + return { + tb: WrapStrategy.CLIP, + }; + } + parseFormulaSync(rule: IDataValidationRule, unitId: string, subUnitId: string) { const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule; const results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid); diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.ts index 650cb79242b..8b7cccd213a 100644 --- a/packages/sheets-data-validation/src/validators/list-validator.ts +++ b/packages/sheets-data-validation/src/validators/list-validator.ts @@ -14,17 +14,17 @@ * limitations under the License. */ -import { DataValidationRenderMode, DataValidationType, isFormulaString, IUniverInstanceService, numfmt, Rectangle, Tools, UniverInstanceType } from '@univerjs/core'; -import type { CellValue, DataValidationOperator, ICellData, IDataValidationRule, IRange, ISheetDataValidationRule, Nullable, Workbook } from '@univerjs/core'; -import type { IBaseDataValidationWidget, IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation'; +import { DataValidationRenderMode, DataValidationType, isFormulaString, IUniverInstanceService, numfmt, Rectangle, Tools, UniverInstanceType, WrapStrategy } from '@univerjs/core'; import { BaseDataValidator } from '@univerjs/data-validation'; import { deserializeRangeWithSheet, isReferenceString, LexerTreeBuilder, sequenceNodeType } from '@univerjs/engine-formula'; -import { LIST_FORMULA_INPUT_NAME } from '../views/formula-input'; -import { LIST_DROPDOWN_KEY } from '../views'; -import { DropdownWidget } from '../widgets/dropdown-widget'; -import { ListRenderModeInput } from '../views/render-mode'; +import type { CellValue, DataValidationOperator, ICellData, IDataValidationRule, IRange, ISheetDataValidationRule, IStyleData, Nullable, Workbook } from '@univerjs/core'; +import type { IBaseDataValidationWidget, IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation'; import { DataValidationFormulaService } from '../services/dv-formula.service'; import { getCellValueOrigin } from '../utils/get-cell-data-origin'; +import { LIST_DROPDOWN_KEY } from '../views'; +import { LIST_FORMULA_INPUT_NAME } from '../views/formula-input'; +import { ListRenderModeInput } from '../views/render-mode'; +import { DropdownWidget } from '../widgets/dropdown-widget'; import { deserializeListOptions } from './util'; export function getRuleFormulaResultSet(result: Nullable[][]>) { @@ -127,6 +127,26 @@ export class ListValidator extends BaseDataValidator { }; } + override getExtraStyle(rule: IDataValidationRule, value: Nullable, { style: defaultStyle }: { style: IStyleData }): Nullable { + if (rule.type === DataValidationType.LIST && (rule.renderMode === DataValidationRenderMode.ARROW || rule.renderMode === DataValidationRenderMode.TEXT)) { + const colorMap = this.getListWithColorMap(rule); + const valueStr = `${value ?? ''}`; + const color = colorMap[valueStr]; + if (color) { + return { + bg: { + rgb: color, + }, + tb: (defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) ?? WrapStrategy.WRAP, + }; + } + } + + return { + tb: (defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) ?? WrapStrategy.WRAP, + }; + } + parseCellValue(cellValue: CellValue) { const cellString = cellValue.toString(); return deserializeListOptions(cellString); From 7bb2facfdcbd80b825888fc2f8102ce0ed845076 Mon Sep 17 00:00:00 2001 From: zw Date: Fri, 13 Sep 2024 02:05:13 +0800 Subject: [PATCH 2/3] feat: update --- .../sheets-data-validation/src/validators/checkbox-validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sheets-data-validation/src/validators/checkbox-validator.ts b/packages/sheets-data-validation/src/validators/checkbox-validator.ts index 24f6c72d2af..7a45cb80d88 100644 --- a/packages/sheets-data-validation/src/validators/checkbox-validator.ts +++ b/packages/sheets-data-validation/src/validators/checkbox-validator.ts @@ -111,7 +111,7 @@ export class CheckboxValidator extends BaseDataValidator { }; } - override getExtraStyle(rule: IDataValidationRule, value: Nullable, ctx) { + override getExtraStyle(rule: IDataValidationRule, value: Nullable) { return { tb: WrapStrategy.CLIP, }; From 6eb9f0cfa14fdfa32c34a3c6c22469b95b77b5e2 Mon Sep 17 00:00:00 2001 From: zw Date: Fri, 13 Sep 2024 02:07:36 +0800 Subject: [PATCH 3/3] feat: update --- .../sheets-data-validation/src/validators/list-validator.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.ts index 8b7cccd213a..ba1aead4b05 100644 --- a/packages/sheets-data-validation/src/validators/list-validator.ts +++ b/packages/sheets-data-validation/src/validators/list-validator.ts @@ -128,6 +128,7 @@ export class ListValidator extends BaseDataValidator { } override getExtraStyle(rule: IDataValidationRule, value: Nullable, { style: defaultStyle }: { style: IStyleData }): Nullable { + const tb = (defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) ?? WrapStrategy.WRAP; if (rule.type === DataValidationType.LIST && (rule.renderMode === DataValidationRenderMode.ARROW || rule.renderMode === DataValidationRenderMode.TEXT)) { const colorMap = this.getListWithColorMap(rule); const valueStr = `${value ?? ''}`; @@ -137,13 +138,13 @@ export class ListValidator extends BaseDataValidator { bg: { rgb: color, }, - tb: (defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) ?? WrapStrategy.WRAP, + tb, }; } } return { - tb: (defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) ?? WrapStrategy.WRAP, + tb, }; }