Skip to content

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.

fix(sheets-data-validation): data validation perf issue on getCell (#3619)

zhangw4f3cd5c50998
diff --git a/packages/core/src/sheets/range.ts b/packages/core/src/sheets/range.ts
index 271370f41a..682fa5485c 100644
--- a/packages/core/src/sheets/range.ts
+++ b/packages/core/src/sheets/range.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import type { IObjectMatrixPrimitiveType, Nullable } from '../shared';
import { ObjectMatrix, Tools } from '../shared';
import { DEFAULT_STYLES } from '../types/const';
-import type { HorizontalAlign, VerticalAlign } from '../types/enum';
import { BooleanNumber, FontItalic, FontWeight, WrapStrategy } from '../types/enum';
+import { RANGE_TYPE } from './typedef';
+import type { IObjectMatrixPrimitiveType, Nullable } from '../shared';
+import type { HorizontalAlign, VerticalAlign } from '../types/enum';
import type {
IBorderData,
IDocumentBody,
@@ -30,7 +31,6 @@ import type {
} from '../types/interfaces';
import type { Styles } from './styles';
import type { ICellData, IRange } from './typedef';
-import { RANGE_TYPE } from './typedef';
import type { Worksheet } from './worksheet';
/**
@@ -123,19 +123,22 @@ export class Range {
}
static transformRange = (range: IRange, worksheet: Worksheet): IRange => {
+ const maxColumns = worksheet.getMaxColumns() - 1;
+ const maxRows = worksheet.getMaxRows() - 1;
+
if (range.rangeType === RANGE_TYPE.ALL) {
return {
startColumn: 0,
startRow: 0,
- endColumn: worksheet.getMaxColumns() - 1,
- endRow: worksheet.getMaxRows() - 1,
+ endColumn: maxColumns,
+ endRow: maxRows,
};
}
if (range.rangeType === RANGE_TYPE.COLUMN) {
return {
startRow: 0,
- endRow: worksheet.getMaxRows() - 1,
+ endRow: maxRows,
startColumn: range.startColumn,
endColumn: range.endColumn,
};
@@ -144,13 +147,18 @@ export class Range {
if (range.rangeType === RANGE_TYPE.ROW) {
return {
startColumn: 0,
- endColumn: worksheet.getMaxColumns() - 1,
+ endColumn: maxColumns,
startRow: range.startRow,
endRow: range.endRow,
};
}
- return range;
+ return {
+ startColumn: range.startColumn,
+ endColumn: Math.min(range.endColumn, maxColumns),
+ startRow: range.startRow,
+ endRow: Math.min(range.endRow, maxRows),
+ };
};
/**
diff --git a/packages/data-validation/src/validators/base-data-validator.ts b/packages/data-validation/src/validators/base-data-validator.ts
index 426a5fe754..f436a47215 100644
--- a/packages/data-validation/src/validators/base-data-validator.ts
+++ b/packages/data-validation/src/validators/base-data-validator.ts
@@ -89,9 +89,7 @@ export abstract class BaseDataValidator<DataType = CellValue> {
return this.localeService.t(this.title);
}
- skipDefaultFontRender(rule: IDataValidationRule, cellValue: Nullable<CellValue>, pos: any) {
- return false;
- };
+ skipDefaultFontRender: ((rule: IDataValidationRule, cellValue: Nullable<CellValue>, pos: any) => boolean) | undefined;
generateRuleName(rule: IDataValidationRuleBase): string {
if (!rule.operator) {
diff --git a/packages/sheets-data-validation/package.json b/packages/sheets-data-validation/package.json
index 69dd757dbe..983ed1004d 100644
--- a/packages/sheets-data-validation/package.json
+++ b/packages/sheets-data-validation/package.json
@@ -80,6 +80,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
+ "@flatten-js/interval-tree": "^1.1.3",
"@univerjs/core": "workspace:*",
"@univerjs/data-validation": "workspace:*",
"@univerjs/design": "workspace:*",
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 ef7a3c6592..33da94afea 100644
--- a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
+++ b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
@@ -14,20 +14,19 @@
* limitations under the License.
*/
-import { DataValidationRenderMode, DataValidationStatus, DataValidationType, ICommandService, Inject, InterceptorEffectEnum, IUniverInstanceService, LifecycleStages, OnLifecycle, Optional, RxDisposable, sequenceExecute, UniverInstanceType, WrapStrategy } from '@univerjs/core';
+import { DataValidationStatus, DataValidationType, ICommandService, Inject, InterceptorEffectEnum, IUniverInstanceService, LifecycleStages, OnLifecycle, Optional, RxDisposable, sequenceExecute, UniverInstanceType } from '@univerjs/core';
import { DataValidatorRegistryService } from '@univerjs/data-validation';
import { IRenderManagerService } from '@univerjs/engine-render';
import { InterceptCellContentPriority, INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';
import { AutoHeightController, IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { IMenuManagerService } from '@univerjs/ui';
import { bufferTime, debounceTime, filter } from 'rxjs';
-import type { ICellDataForSheetInterceptor, ICellRenderContext, IRange, Workbook } from '@univerjs/core';
+import type { CellValue, ICellRenderContext, IRange, Nullable, Workbook } from '@univerjs/core';
import type { Spreadsheet } from '@univerjs/engine-render';
import { SheetDataValidationModel } from '../models/sheet-data-validation-model';
import { DataValidationDropdownManagerService } from '../services/dropdown-manager.service';
import { getCellValueOrigin } from '../utils/get-cell-data-origin';
import { menuSchema } from './menu.schema';
-import type { ListValidator } from '../validators';
const INVALID_MARK = {
tr: {
@@ -165,11 +164,10 @@ export class SheetsDataValidationRenderController extends RxDisposable {
effect: InterceptorEffectEnum.Style,
// must be after numfmt
priority: InterceptCellContentPriority.DATA_VALIDATION,
- // eslint-disable-next-line complexity
+ // eslint-disable-next-line max-lines-per-function, complexity
handler: (cell, pos, next) => {
const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
- 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);
@@ -180,9 +178,22 @@ export class SheetsDataValidationRenderController extends RxDisposable {
}
const validStatus = this._sheetDataValidationModel.validator(cell, rule, pos);
const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
- const cellOrigin = worksheet.getCellRaw(row, col);
- const cellValue = getCellValueOrigin(cellOrigin);
- const valueStr = `${getCellValueOrigin(cellOrigin) ?? ''}`;
+ const cellOrigin = pos.rawData;
+ let cache: Nullable<CellValue>;
+ const cellValue = {
+ get value() {
+ if (cache !== undefined) {
+ return cache;
+ }
+ cache = getCellValueOrigin(cellOrigin) ?? null;
+ return cache;
+ },
+ };
+ const valueStr = {
+ get value() {
+ return `${cellValue.value ?? ''}`;
+ },
+ };
return next({
...cell,
@@ -202,11 +213,16 @@ export class SheetsDataValidationRenderController extends RxDisposable {
],
fontRenderExtension: {
...cell?.fontRenderExtension,
- isSkip: cell?.fontRenderExtension?.isSkip || validator?.skipDefaultFontRender(rule, cellValue, pos),
+ isSkip: cell?.fontRenderExtension?.isSkip || validator?.skipDefaultFontRender?.(rule, cellValue.value, pos),
},
interceptorStyle: {
...cell?.interceptorStyle,
- ...validator?.getExtraStyle(rule, valueStr, { style: defaultStyle }),
+ ...validator?.getExtraStyle(rule, valueStr.value, {
+ get style() {
+ const styleMap = workbook.getStyles();
+ return (typeof cell?.s === 'string' ? styleMap.get(cell?.s) : cell?.s) || {};
+ },
+ }),
},
interceptorAutoHeight: () => {
const skeleton = this._renderManagerService.getRenderById(unitId)
@@ -324,27 +340,17 @@ export class SheetsDataValidationMobileRenderController extends RxDisposable {
INTERCEPTOR_POINT.CELL_CONTENT,
{
effect: InterceptorEffectEnum.Style,
+ // 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 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);
}
@@ -352,47 +358,10 @@ export class SheetsDataValidationMobileRenderController 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 = `${cellValue ?? ''}`;
return next({
...cell,
- ...extra,
dataValidation: {
ruleId,
validStatus,
@@ -407,21 +376,27 @@ export class SheetsDataValidationMobileRenderController extends RxDisposable {
...(cell?.customRender ?? []),
...(validator?.canvasRender ? [validator.canvasRender] : []),
],
- // @ts-ignore
fontRenderExtension: {
- // @ts-ignore
...cell?.fontRenderExtension,
- isSkip: validator?.skipDefaultFontRender(rule, cellValue, pos),
+ isSkip: cell?.fontRenderExtension?.isSkip || validator?.skipDefaultFontRender?.(rule, cellValue, pos),
},
interceptorStyle: {
...cell?.interceptorStyle,
- ...extra.interceptorStyle,
+ ...validator?.getExtraStyle(rule, valueStr, {
+ get style() {
+ const styleMap = workbook.getStyles();
+ return (typeof cell?.s === 'string' ? styleMap.get(cell?.s) : cell?.s) || {};
+ },
+ }),
},
interceptorAutoHeight: () => {
- // const mergeCell = skeleton.mergeData.find((range) => {
- // const { startColumn, startRow, endColumn, endRow } = range;
- // return row >= startRow && col >= startColumn && row <= endRow && col <= endColumn;
- // });
+ const skeleton = this._renderManagerService.getRenderById(unitId)
+ ?.with(SheetSkeletonManagerService)
+ .getWorksheetSkeleton(subUnitId)
+ ?.skeleton;
+ if (!skeleton) {
+ return undefined;
+ }
const mergeCell = skeleton.worksheet.getMergedCell(row, col);
const info: ICellRenderContext = {
@@ -440,11 +415,12 @@ export class SheetsDataValidationMobileRenderController extends RxDisposable {
subUnitId,
row,
col,
- worksheet,
workbook,
+ worksheet,
};
return validator?.canvasRender?.calcCellAutoHeight?.(info);
},
+ coverable: (cell?.coverable ?? true) && !(rule.type === DataValidationType.LIST || rule.type === DataValidationType.LIST_MULTIPLE),
});
},
}
diff --git a/packages/sheets-data-validation/src/models/rule-matrix.ts b/packages/sheets-data-validation/src/models/rule-matrix.ts
index b8a3c978f8..70c59005aa 100644
--- a/packages/sheets-data-validation/src/models/rule-matrix.ts
+++ b/packages/sheets-data-validation/src/models/rule-matrix.ts
@@ -14,8 +14,15 @@
* limitations under the License.
*/
-import { Range, Rectangle, Tools } from '@univerjs/core';
-import type { IRange, ISheetDataValidationRule, Worksheet } from '@univerjs/core';
+import IntervalTree from '@flatten-js/interval-tree';
+import { debounce, Range, Rectangle, Tools, UniverInstanceType } from '@univerjs/core';
+import type { IRange, ISheetDataValidationRule, IUniverInstanceService, Workbook } from '@univerjs/core';
+
+interface IRuleItem {
+ ruleId: string;
+ startRow: number;
+ endRow: number;
+}
export type RangeMutation = {
type: 'update';
@@ -32,18 +39,68 @@ export type RangeMutation = {
};
export class RuleMatrix {
- private _map = new Map<string, IRange[]>();
+ private _map: Map<string, IRange[]>;
+ private _tree = new Map<number, IntervalTree<string>>();
+ private _dirty = true;
constructor(
value: Map<string, IRange[]>,
- private _worksheet: Worksheet
+ private _unitId: string,
+ private _subUnitId: string,
+ private _univerInstanceService: IUniverInstanceService,
+ private _disableTree = false
) {
this._map = value;
+ this._buildTree();
+ }
+
+ private _buildTree = () => {
+ if (!this._dirty || this._disableTree) {
+ return;
+ }
+ const map = new Map<number, IRuleItem[]>();
+ this._map.forEach((ranges, ruleId) => {
+ ranges.forEach((range) => {
+ for (let col = range.startColumn; col <= range.endColumn; col++) {
+ let items = map.get(col);
+ if (!items) {
+ items = [];
+ map.set(col, items);
+ }
+ items.push({
+ startRow: range.startRow,
+ endRow: range.endRow,
+ ruleId,
+ });
+ }
+ });
+ });
+ const treeMap = new Map<number, IntervalTree<string>>();
+ map.forEach((items, col) => {
+ const tree = new IntervalTree<string>();
+ items.forEach((item) => {
+ tree.insert([item.startRow, item.endRow], item.ruleId);
+ });
+
+ treeMap.set(col, tree);
+ });
+ this._tree = treeMap;
+ this._dirty = false;
+ };
+
+ private _debonceBuildTree = debounce(this._buildTree, 0);
+
+ get _worksheet() {
+ return this._univerInstanceService.getUnit<Workbook>(this._unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(this._subUnitId);
}
addRule(rule: ISheetDataValidationRule) {
+ if (!this._worksheet) {
+ return;
+ }
+
const ruleId = rule.uid;
- const ranges = rule.ranges.map((range) => Range.transformRange(range, this._worksheet));
+ const ranges = rule.ranges.map((range) => Range.transformRange(range, this._worksheet!));
this._map.forEach((value, key) => {
const newRanges = Rectangle.subtractMulti(value, ranges);
@@ -54,11 +111,16 @@ export class RuleMatrix {
}
});
+ this._dirty = true;
this._map.set(ruleId, ranges);
+ this._debonceBuildTree();
}
removeRange(_ranges: IRange[]) {
- const ranges = _ranges.map((range) => Range.transformRange(range, this._worksheet));
+ if (!this._worksheet) {
+ return;
+ }
+ const ranges = _ranges.map((range) => Range.transformRange(range, this._worksheet!));
this._map.forEach((value, key) => {
const newRanges = Rectangle.subtractMulti(value, ranges);
if (newRanges.length === 0) {
@@ -67,15 +129,23 @@ export class RuleMatrix {
this._map.set(key, newRanges);
}
});
+ this._dirty = true;
+ this._debonceBuildTree();
}
removeRule(rule: ISheetDataValidationRule) {
this._map.delete(rule.uid);
+ this._dirty = true;
+ this._debonceBuildTree();
}
updateRange(ruleId: string, _newRanges: IRange[]) {
+ if (!this._worksheet) {
+ return;
+ }
this._map.delete(ruleId);
- const ranges = _newRanges.map((range) => Range.transformRange(range, this._worksheet));
+ const ranges = _newRanges.map((range) => Range.transformRange(range, this._worksheet!));
+
this._map.forEach((value, key) => {
const newRanges = Rectangle.subtractMulti(value, ranges);
if (newRanges.length === 0) {
@@ -84,8 +154,40 @@ export class RuleMatrix {
this._map.set(key, newRanges);
}
});
-
this._map.set(ruleId, ranges);
+ this._dirty = true;
+ this._debonceBuildTree();
+ }
+
+ addRangeRules(rules: { id: string;ranges: IRange[] }[]) {
+ rules.forEach(({ id: ruleId, ranges }) => {
+ if (!ranges.length) {
+ return;
+ }
+
+ let current = this._map.get(ruleId);
+ if (!current) {
+ current = ranges;
+ this._map.set(ruleId, current);
+ } else {
+ this._map.set(ruleId, Rectangle.mergeRanges([...current, ...ranges]));
+ current = this._map.get(ruleId)!;
+ }
+
+ this._map.forEach((value, key) => {
+ if (key === ruleId) {
+ return;
+ }
+ const newRanges = Rectangle.subtractMulti(value, ranges);
+ if (newRanges.length === 0) {
+ this._map.delete(key);
+ } else {
+ this._map.set(key, newRanges);
+ }
+ });
+ });
+ this._dirty = true;
+ this._debonceBuildTree();
}
diff(rules: ISheetDataValidationRule[]) {
@@ -95,7 +197,7 @@ export class RuleMatrix {
const newRanges = this._map.get(rule.uid) ?? [];
const oldRanges = rule.ranges;
- if (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) {
+ if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i])))) {
mutations.push({
type: 'update',
ruleId: rule.uid,
@@ -124,7 +226,7 @@ export class RuleMatrix {
const newRanges = this._map.get(rule.uid) ?? [];
const oldRanges = rule.ranges;
- if (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) {
+ if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i])))) {
mutations.push({
type: 'update',
ruleId: rule.uid,
@@ -158,45 +260,25 @@ export class RuleMatrix {
}
clone() {
- return new RuleMatrix(new Map(Tools.deepClone(Array.from(this._map.entries()))), this._worksheet);
+ return new RuleMatrix(
+ new Map(Tools.deepClone(Array.from(this._map.entries()))),
+ this._unitId,
+ this._subUnitId,
+ this._univerInstanceService,
+ // disable tree on cloned matrix, cause there is no need to search
+ true
+ );
}
- getValue(row: number, col: number) {
- const keys = Array.from(this._map.keys());
- for (const id of keys) {
- const ranges = this._map.get(id) ?? [];
- if (ranges.find((range) => range.startRow <= row && range.endRow >= row && range.startColumn <= col && range.endColumn >= col)) {
- return id;
- }
+ getValue(row: number, col: number): string | undefined {
+ if (this._dirty) {
+ this._buildTree();
}
- }
-
- addRangeRules(rules: { id: string;ranges: IRange[] }[]) {
- rules.forEach(({ id: ruleId, ranges }) => {
- if (!ranges.length) {
- return;
- }
-
- let current = this._map.get(ruleId);
- if (!current) {
- current = ranges;
- this._map.set(ruleId, current);
- } else {
- this._map.set(ruleId, Rectangle.mergeRanges([...current, ...ranges]));
- current = this._map.get(ruleId)!;
- }
-
- this._map.forEach((value, key) => {
- if (key === ruleId) {
- return;
- }
- const newRanges = Rectangle.subtractMulti(value, ranges);
- if (newRanges.length === 0) {
- this._map.delete(key);
- } else {
- this._map.set(key, newRanges);
- }
- });
- });
+ const tree = this._tree.get(col);
+ if (!tree) {
+ return undefined;
+ }
+ const result = tree.search([row, row]);
+ return result.length > 0 ? result[0] : undefined;
}
}
diff --git a/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts b/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts
index 1a8dbd42e2..b44ef3952f 100644
--- a/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts
+++ b/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-import { DataValidationStatus, DataValidationType, Disposable, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
+import type { DataValidationType, ICellDataForSheetInterceptor, ISheetDataValidationRule, Nullable } from '@univerjs/core';
+import type { IRuleChange, IUpdateRulePayload, IValidStatusChange } from '@univerjs/data-validation';
+import type { IRemoveSheetMutationParams, ISheetLocation } from '@univerjs/sheets';
+import { DataValidationStatus, Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryService, UpdateRuleType } from '@univerjs/data-validation';
-import { isReferenceString } from '@univerjs/engine-formula';
+import { RemoveSheetMutation } from '@univerjs/sheets';
import { Subject } from 'rxjs';
-import type { ICellDataForSheetInterceptor, ISheetDataValidationRule, Nullable, Workbook } from '@univerjs/core';
-import type { IRuleChange, IUpdateRulePayload, IValidStatusChange } from '@univerjs/data-validation';
-import type { ISheetLocation } from '@univerjs/sheets';
import { DataValidationCacheService } from '../services/dv-cache.service';
import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';
import { DataValidationFormulaService } from '../services/dv-formula.service';
@@ -42,7 +42,8 @@ export class SheetDataValidationModel extends Disposable {
@Inject(DataValidatorRegistryService) private _dataValidatorRegistryService: DataValidatorRegistryService,
@Inject(DataValidationCacheService) private _dataValidationCacheService: DataValidationCacheService,
@Inject(DataValidationFormulaService) private _dataValidationFormulaService: DataValidationFormulaService,
- @Inject(DataValidationCustomFormulaService) private _dataValidationCustomFormulaService: DataValidationCustomFormulaService
+ @Inject(DataValidationCustomFormulaService) private _dataValidationCustomFormulaService: DataValidationCustomFormulaService,
+ @ICommandService private readonly _commandService: ICommandService
) {
super();
this._initRuleUpdateListener();
@@ -51,6 +52,28 @@ export class SheetDataValidationModel extends Disposable {
this._ruleChange$.complete();
this._validStatusChange$.complete();
});
+
+ this._initUniverInstanceListener();
+ }
+
+ private _initUniverInstanceListener() {
+ this.disposeWithMe(
+ this._univerInstanceService.unitDisposed$.subscribe((unit) => {
+ this._ruleMatrixMap.delete(unit.getUnitId());
+ })
+ );
+
+ this.disposeWithMe(
+ this._commandService.onCommandExecuted((command) => {
+ if (command.id === RemoveSheetMutation.id) {
+ const { unitId, subUnitId } = command.params as IRemoveSheetMutationParams;
+ const subUnitMap = this._ruleMatrixMap.get(unitId);
+ if (subUnitMap) {
+ subUnitMap.delete(subUnitId);
+ }
+ }
+ })
+ );
}
private _initRuleUpdateListener() {
@@ -90,10 +113,7 @@ export class SheetDataValidationModel extends Disposable {
private _ensureRuleMatrix(unitId: string, subUnitId: string) {
let unitMap = this._ruleMatrixMap.get(unitId);
- const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);
- if (!workbook) {
- throw new Error(`workbook not found, unitId: ${unitId}`);
- }
+
if (!unitMap) {
unitMap = new Map();
this._ruleMatrixMap.set(unitId, unitMap);
@@ -101,11 +121,7 @@ export class SheetDataValidationModel extends Disposable {
let matrix = unitMap.get(subUnitId);
if (!matrix) {
- const worksheet = workbook.getSheetBySheetId(subUnitId);
- if (!worksheet) {
- throw new Error(`worksheet not found, unitId: ${unitId}, subUnitId: ${subUnitId}`);
- }
- matrix = new RuleMatrix(new Map(), worksheet);
+ matrix = new RuleMatrix(new Map(), unitId, subUnitId, this._univerInstanceService);
unitMap.set(subUnitId, matrix);
}
@@ -113,12 +129,6 @@ export class SheetDataValidationModel extends Disposable {
}
private _addRuleSideEffect(unitId: string, subUnitId: string, rule: ISheetDataValidationRule) {
- if (rule.type === DataValidationType.LIST || rule.type === DataValidationType.LIST_MULTIPLE) {
- if (isReferenceString(rule.formula1 ?? '')) {
- // polyfill old-version ref-string, transform to formula
- rule.formula1 = `=${rule.formula1}`;
- }
- }
const ruleMatrix = this._ensureRuleMatrix(unitId, subUnitId);
ruleMatrix.addRule(rule);
this._dataValidationCacheService.addRule(unitId, subUnitId, rule);
diff --git a/packages/sheets-data-validation/src/plugin.ts b/packages/sheets-data-validation/src/plugin.ts
index f233b1ecc0..0712ecd3f1 100644
--- a/packages/sheets-data-validation/src/plugin.ts
+++ b/packages/sheets-data-validation/src/plugin.ts
@@ -61,7 +61,7 @@ export class UniverSheetsDataValidationPlugin extends Plugin {
) {
super();
- // Manage the plugin configuration.
+ // Manage the plugin configuration..
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
diff --git a/packages/sheets-data-validation/src/validators/checkbox-validator.ts b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
index 7a45cb80d8..dfcfbcc738 100644
--- a/packages/sheets-data-validation/src/validators/checkbox-validator.ts
+++ b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
@@ -61,14 +61,14 @@ export class CheckboxValidator extends BaseDataValidator {
private _formulaService = this.injector.get(DataValidationFormulaService);
- override skipDefaultFontRender(rule: ISheetDataValidationRule, cellValue: Nullable<CellValue>, pos: { unitId: string; subUnitId: string }) {
+ override skipDefaultFontRender = (rule: ISheetDataValidationRule, cellValue: Nullable<CellValue>, pos: { unitId: string; subUnitId: string }) => {
const { formula1, formula2 } = this.parseFormulaSync(rule, pos.unitId, pos.subUnitId);
const valueStr = `${cellValue ?? ''}`;
const res = !valueStr || (valueStr === (`${formula1}`) || valueStr === `${formula2}`);
return res;
- }
+ };
override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const { formula1, formula2 } = rule;
diff --git a/packages/sheets-data-validation/src/validators/list-multiple-validator.ts b/packages/sheets-data-validation/src/validators/list-multiple-validator.ts
index b59f63feb4..db4914fcf5 100644
--- a/packages/sheets-data-validation/src/validators/list-multiple-validator.ts
+++ b/packages/sheets-data-validation/src/validators/list-multiple-validator.ts
@@ -23,7 +23,7 @@ export class ListMultipleValidator extends ListValidator {
override title: string = 'dataValidation.listMultiple.title';
override canvasRender = this.injector.createInstance(DropdownMultipleWidget);
- override skipDefaultFontRender() {
+ override skipDefaultFontRender = () => {
return true;
- }
+ };
}
diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.ts
index a715379b4b..64b2e7420a 100644
--- a/packages/sheets-data-validation/src/validators/list-validator.ts
+++ b/packages/sheets-data-validation/src/validators/list-validator.ts
@@ -105,9 +105,9 @@ export class ListValidator extends BaseDataValidator {
override optionsInput: string | undefined = ListRenderModeInput.componentKey;
- override skipDefaultFontRender(rule: ISheetDataValidationRule) {
+ override skipDefaultFontRender = (rule: ISheetDataValidationRule) => {
return rule.renderMode !== DataValidationRenderMode.TEXT;
- }
+ };
override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const success = !Tools.isBlank(rule.formula1);
diff --git a/packages/sheets-data-validation/src/views/detail/index.module.less b/packages/sheets-data-validation/src/views/detail/index.module.less
index c48602a957..17c9c703e2 100644
--- a/packages/sheets-data-validation/src/views/detail/index.module.less
+++ b/packages/sheets-data-validation/src/views/detail/index.module.less
@@ -1,4 +1,6 @@
.data-validation-detail {
+ padding: var(--padding-base) 0;
+
&-form-item {
width: 100%;
}
diff --git a/packages/sheets-data-validation/src/views/detail/index.tsx b/packages/sheets-data-validation/src/views/detail/index.tsx
index 862fad3bb3..ea27875e7b 100644
--- a/packages/sheets-data-validation/src/views/detail/index.tsx
+++ b/packages/sheets-data-validation/src/views/detail/index.tsx
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+import type { DataValidationOperator, DataValidationType, IDataValidationRuleBase, IDataValidationRuleOptions, IExecutionOptions, ISheetDataValidationRule, IUnitRange } from '@univerjs/core';
+import type { IUpdateSheetDataValidationRangeCommandParams } from '../../commands/commands/data-validation.command';
import { createInternalEditorID, debounce, ICommandService, isUnitRangesEqual, isValidRange, LocaleService, RedoCommand, shallowEqual, UndoCommand, useDependency } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryScope, DataValidatorRegistryService, getRuleOptions, getRuleSetting, TWO_FORMULA_OPERATOR_COUNT } from '@univerjs/data-validation';
import { Button, FormLayout, Select } from '@univerjs/design';
@@ -21,12 +23,10 @@ import { RangeSelector } from '@univerjs/docs-ui';
import { serializeRange } from '@univerjs/engine-formula';
import { ComponentManager, useEvent, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useState } from 'react';
-import type { DataValidationOperator, DataValidationType, IDataValidationRuleBase, IDataValidationRuleOptions, IExecutionOptions, ISheetDataValidationRule, IUnitRange } from '@univerjs/core';
import { RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand } from '../../commands/commands/data-validation.command';
import { DataValidationPanelService } from '../../services/data-validation-panel.service';
import { DataValidationOptions } from '../options';
import styles from './index.module.less';
-import type { IUpdateSheetDataValidationRangeCommandParams } from '../../commands/commands/data-validation.command';
// debounce execute commands, for better redo-undo experience
const debounceExecuteFactory = (commandService: ICommandService) => debounce(
@@ -211,7 +211,7 @@ export function DataValidationDetail() {
);
};
return (
- <div>
+ <div className={styles.dataValidationDetail}>
<FormLayout
label={localeService.t('dataValidation.panel.range')}
error={!localRule.ranges.length ? localeService.t('dataValidation.panel.rangeError') : ''}
diff --git a/packages/sheets-data-validation/src/views/list/index.module.less b/packages/sheets-data-validation/src/views/list/index.module.less
index bd63f402d3..bdfdf72fe9 100644
--- a/packages/sheets-data-validation/src/views/list/index.module.less
+++ b/packages/sheets-data-validation/src/views/list/index.module.less
@@ -1,4 +1,6 @@
.data-validation-list {
+ padding: var(--padding-base) 0;
+
&-buttons {
margin-top: 20px;
display: flex;
diff --git a/packages/sheets-data-validation/src/views/list/index.tsx b/packages/sheets-data-validation/src/views/list/index.tsx
index 7dd99f0ed5..371fbab78d 100644
--- a/packages/sheets-data-validation/src/views/list/index.tsx
+++ b/packages/sheets-data-validation/src/views/list/index.tsx
@@ -14,19 +14,19 @@
* limitations under the License.
*/
+import type { ISheetDataValidationRule, Workbook } from '@univerjs/core';
+import type { IAddSheetDataValidationCommandParams } from '../../commands/commands/data-validation.command';
import { ICommandService, Injector, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
import { Button } from '@univerjs/design';
import { checkRangesEditablePermission } from '@univerjs/sheets';
import { useObservable } from '@univerjs/ui';
import React, { useEffect, useState } from 'react';
-import type { ISheetDataValidationRule, Workbook } from '@univerjs/core';
import { AddSheetDataValidationCommand, RemoveSheetAllDataValidationCommand } from '../../commands/commands/data-validation.command';
import { SheetDataValidationModel } from '../../models/sheet-data-validation-model';
import { DataValidationPanelService } from '../../services/data-validation-panel.service';
import { createDefaultNewRule } from '../../utils/create';
import { DataValidationItem } from '../item';
import styles from './index.module.less';
-import type { IAddSheetDataValidationCommandParams } from '../../commands/commands/data-validation.command';
export function DataValidationList() {
const univerInstanceService = useDependency(IUniverInstanceService);
@@ -112,7 +112,7 @@ function DataValidationListWithWorkbook(props: { workbook: Workbook }) {
const hasDisableRule = rulesByPermissionCheck?.some((rule) => rule.disable);
return (
- <div>
+ <div className={styles.dataValidationList}>
{rulesByPermissionCheck?.map((rule) => (
<DataValidationItem
unitId={unitId}
diff --git a/packages/sheets-data-validation/src/widgets/checkbox-widget.ts b/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
index e476306458..2646265c41 100644
--- a/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
+++ b/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
@@ -103,7 +103,7 @@ export class CheckboxRender implements IBaseDataValidationWidget {
}
const colors = this._themeService.getCurrentTheme();
- if (!validator.skipDefaultFontRender(rule, value, { unitId: unitId!, subUnitId })) {
+ if (!validator.skipDefaultFontRender?.(rule, value, { unitId: unitId!, subUnitId })) {
return;
}
@@ -178,7 +178,7 @@ export class CheckboxRender implements IBaseDataValidationWidget {
return;
}
- if (!validator.skipDefaultFontRender(rule, value, { unitId, subUnitId })) {
+ if (!validator.skipDefaultFontRender?.(rule, value, { unitId, subUnitId })) {
return;
}
diff --git a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
index e7725033ea..a85e32d287 100644
--- a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
+++ b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-import { BooleanNumber, DataValidationRenderMode, DataValidationType, DEFAULT_EMPTY_DOCUMENT_VALUE, DEFAULT_STYLES, DocumentDataModel, HorizontalAlign, ICommandService, Inject, LocaleService, Tools, VerticalAlign, WrapStrategy } from '@univerjs/core';
import type { ICellRenderContext, IDocumentData, IPaddingData, IStyleData, Nullable } from '@univerjs/core';
-import { Documents, DocumentSkeleton, DocumentViewModel, getDocsSkeletonPageSize, Rect } from '@univerjs/engine-render';
-import type { IMouseEvent, IPointerEvent, SpreadsheetSkeleton, UniverRenderingContext, UniverRenderingContext2D } from '@univerjs/engine-render';
import type { IBaseDataValidationWidget } from '@univerjs/data-validation';
-import { getCellValueOrigin } from '../utils/get-cell-data-origin';
+import type { IMouseEvent, IPointerEvent, SpreadsheetSkeleton, UniverRenderingContext, UniverRenderingContext2D } from '@univerjs/engine-render';
+import type { ListValidator } from '../validators';
+import { BooleanNumber, DataValidationRenderMode, DataValidationType, DEFAULT_EMPTY_DOCUMENT_VALUE, DEFAULT_STYLES, DocumentDataModel, HorizontalAlign, ICommandService, Inject, LocaleService, Tools, VerticalAlign, WrapStrategy } from '@univerjs/core';
+import { Documents, DocumentSkeleton, DocumentViewModel, getDocsSkeletonPageSize, Rect } from '@univerjs/engine-render';
import { type IShowDataValidationDropdownParams, ShowDataValidationDropdown } from '../commands/operations/data-validation.operation';
import { DROP_DOWN_DEFAULT_COLOR } from '../common/const';
-import type { ListValidator } from '../validators';
+import { getCellValueOrigin } from '../utils/get-cell-data-origin';
const PADDING_H = 4;
const ICON_SIZE = 4;
@@ -115,12 +115,11 @@ function calcPadding(cellWidth: number, cellHeight: number, fontWidth: number, f
const realMargin = margin ? MARGIN_V : 0;
switch (vt) {
case VerticalAlign.BOTTOM:
- paddingTop = (cellHeight - (realMargin * 2) - fontHeight) + realMargin;
+ paddingTop = cellHeight - fontHeight - realMargin;
break;
case VerticalAlign.MIDDLE:
- paddingTop = ((cellHeight - (realMargin * 2) - fontHeight) / 2) + realMargin;
+ paddingTop = (cellHeight - fontHeight) / 2;
break;
-
default:
paddingTop = realMargin;
break;
@@ -194,19 +193,17 @@ export class DropdownWidget implements IBaseDataValidationWidget {
const { t = DEFAULT_STYLES.pd.t, b = DEFAULT_STYLES.pd.b } = pd;
const left = cellWidth - ICON_PLACE;
let top;
-
switch (vt) {
case VerticalAlign.MIDDLE:
top = (cellHeight - ICON_SIZE) / 2;
break;
case VerticalAlign.BOTTOM:
- top = cellHeight - (ICON_SIZE / 2) - b - (fontHeight / 2);
+ top = (cellHeight - b - fontHeight - MARGIN_V) + (fontHeight / 2 - ICON_SIZE / 2);
break;
default:
- top = t + (fontHeight / 2) - (ICON_SIZE / 2);
+ top = t + MARGIN_V + (fontHeight / 2 - ICON_SIZE / 2);
break;
}
-
ctx.save();
ctx.translateWithPrecision(cellBounding.startX + left, cellBounding.startY + top);
ctx.fillStyle = '#565656';
@@ -267,9 +264,8 @@ export class DropdownWidget implements IBaseDataValidationWidget {
documentSkeleton.calculate();
documentSkeleton.getActualSize();
const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
-
const { height: fontHeight, width: fontWidth } = textLayout;
- const { paddingTop, paddingLeft } = calcPadding(realWidth, cellHeight - t - b, fontWidth, fontHeight, vt, ht, false);
+ const { paddingTop, paddingLeft } = calcPadding(realWidth, cellHeight - t - b, fontWidth, fontHeight, vt, ht, true);
this._drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, fontHeight, vt, pd);
ctx.save();
@@ -390,10 +386,9 @@ export class DropdownWidget implements IBaseDataValidationWidget {
documentSkeleton.calculate();
documentSkeleton.getActualSize();
const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
-
const { height: fontHeight } = textLayout;
- return fontHeight + t + b;
+ return fontHeight + t + b + MARGIN_V * 2;
} else {
const realWidth = cellWidth - (MARGIN_H * 2) - PADDING_H - ICON_PLACE;
const { documentSkeleton, docModel } = createDocSkeleton(valueStr, this._localeService, style);
diff --git a/packages/sheets-filter-ui/src/commands/commands/sheets-filter.command.ts b/packages/sheets-filter-ui/src/commands/commands/sheets-filter.command.ts
index 68c9ef3b90..93c11d2e73 100644
--- a/packages/sheets-filter-ui/src/commands/commands/sheets-filter.command.ts
+++ b/packages/sheets-filter-ui/src/commands/commands/sheets-filter.command.ts
@@ -14,14 +14,14 @@
* limitations under the License.
*/
+import type { IAccessor, ICommand, IMutationInfo, IRange, Nullable, Workbook } from '@univerjs/core';
+import type { ISheetCommandSharedParams } from '@univerjs/sheets';
+import type { FilterColumn, IAutoFilter, IFilterColumn, ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '@univerjs/sheets-filter';
import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, LocaleService, Quantity, sequenceExecute, UniverInstanceType } from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { expandToContinuousRange, getSheetCommandTarget, isSingleCellSelection, SheetsSelectionsService } from '@univerjs/sheets';
import { ReCalcSheetsFilterMutation, RemoveSheetsFilterMutation, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation, SheetsFilterService } from '@univerjs/sheets-filter';
import { IMessageService } from '@univerjs/ui';
-import type { IAccessor, ICommand, IMutationInfo, IRange, Nullable, Workbook } from '@univerjs/core';
-import type { ISheetCommandSharedParams } from '@univerjs/sheets';
-import type { FilterColumn, IAutoFilter, IFilterColumn, ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '@univerjs/sheets-filter';
/**
* Parameters of command {@link SetSheetFilterRangeCommand}.
diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx
index 9860172d7b..008b4fe2c9 100644
--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx
+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { ByValuesModel, IFilterByValueItem } from '../../services/sheets-filter-panel.service';
import { LocaleService, useDependency } from '@univerjs/core';
import { Button, Checkbox, Input, Tooltip } from '@univerjs/design';
import { useObservable } from '@univerjs/ui';
@@ -21,7 +22,6 @@ import List from 'rc-virtual-list';
import React, { useCallback } from 'react';
import { statisticFilterByValueItems } from '../../models/utils';
import styles from './index.module.less';
-import type { ByValuesModel, IFilterByValueItem } from '../../services/sheets-filter-panel.service';
/**
* Filter by values.
diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
index ac8d4de536..8089b85d09 100644
--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
@@ -14,11 +14,12 @@
* limitations under the License.
*/
+import type { ByConditionsModel, ByValuesModel } from '../../services/sheets-filter-panel.service';
import { ICommandService, LocaleService, useDependency } from '@univerjs/core';
import { Button, type ISegmentedProps, Segmented } from '@univerjs/design';
import { SheetsFilterService } from '@univerjs/sheets-filter';
-import { SheetsUIPart } from '@univerjs/sheets-ui';
+import { SheetsUIPart } from '@univerjs/sheets-ui';
import { ComponentContainer, useComponentsOfPart, useObservable } from '@univerjs/ui';
import React, { useCallback, useMemo } from 'react';
import { of } from 'rxjs';
@@ -27,7 +28,6 @@ import { FilterBy, SheetsFilterPanelService } from '../../services/sheets-filter
import styles from './index.module.less';
import { FilterByCondition } from './SheetsFilterByConditionsPanel';
import { FilterByValue } from './SheetsFilterByValuesPanel';
-import type { ByConditionsModel, ByValuesModel } from '../../services/sheets-filter-panel.service';
/**
* This Filter Panel component is used to filter the data in the sheet.
diff --git a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts b/packages/sheets-filter/src/controllers/sheets-filter.controller.ts
index b83949a0e1..8c84d15c11 100644
--- a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts
+++ b/packages/sheets-filter/src/controllers/sheets-filter.controller.ts
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-import { Disposable, DisposableCollection, ICommandService, Inject, IUniverInstanceService, moveMatrixArray, Rectangle } from '@univerjs/core';
-import { CopySheetCommand, EffectRefRangId, expandToContinuousRange, getSheetCommandTarget, InsertColCommand, InsertRowCommand, InsertRowMutation, INTERCEPTOR_POINT, MoveRangeCommand, MoveRowsCommand, RefRangeService, RemoveColCommand, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, SetRangeValuesMutation, SetWorksheetActiveOperation, SheetInterceptorService } from '@univerjs/sheets';
import type { ICellData, ICommandInfo, IMutationInfo, IObjectArrayPrimitiveType, IRange, Nullable, Workbook } from '@univerjs/core';
import type { EffectRefRangeParams, IAddWorksheetMergeMutationParams, ICopySheetCommandParams, IInsertColCommandParams, IInsertRowCommandParams, IInsertRowMutationParams, IMoveColsCommandParams, IMoveRangeCommandParams, IMoveRowsCommandParams, IRemoveColMutationParams, IRemoveRowsMutationParams, IRemoveSheetCommandParams, ISetRangeValuesMutationParams, ISetWorksheetActiveOperationParams, ISheetCommandSharedParams } from '@univerjs/sheets';
+import type { ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '../commands/mutations/sheets-filter.mutation';
+import type { FilterColumn } from '../models/filter-model';
+import { Disposable, DisposableCollection, ICommandService, Inject, IUniverInstanceService, moveMatrixArray, Rectangle } from '@univerjs/core';
+import { CopySheetCommand, EffectRefRangId, expandToContinuousRange, getSheetCommandTarget, InsertColCommand, InsertRowCommand, InsertRowMutation, INTERCEPTOR_POINT, MoveRangeCommand, MoveRowsCommand, RefRangeService, RemoveColCommand, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, SetRangeValuesMutation, SetWorksheetActiveOperation, SheetInterceptorService } from '@univerjs/sheets';
import { ReCalcSheetsFilterMutation, RemoveSheetsFilterMutation, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation } from '../commands/mutations/sheets-filter.mutation';
import { SheetsFilterService } from '../services/sheet-filter.service';
import { mergeSetFilterCriteria } from '../utils';
-import type { ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '../commands/mutations/sheets-filter.mutation';
-import type { FilterColumn } from '../models/filter-model';
export class SheetsFilterController extends Disposable {
private _disposableCollection: DisposableCollection = new DisposableCollection();
diff --git a/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts b/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts
index 192a67ca72..f948f77557 100644
--- a/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts
+++ b/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts
@@ -14,14 +14,6 @@
* limitations under the License.
*/
-import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import {
- InsertSheetMutation,
- RemoveSheetMutation,
- SetSelectionsOperation,
- SetWorksheetActiveOperation,
- SetWorksheetHideMutation,
-} from '@univerjs/sheets';
import type { IMutationInfo, IOperationInfo, Workbook } from '@univerjs/core';
import type {
IInsertSheetMutationParams,
@@ -30,6 +22,14 @@ import type {
ISetWorksheetActiveOperationParams,
ISetWorksheetHideMutationParams,
} from '@univerjs/sheets';
+import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import {
+ InsertSheetMutation,
+ RemoveSheetMutation,
+ SetSelectionsOperation,
+ SetWorksheetActiveOperation,
+ SetWorksheetHideMutation,
+} from '@univerjs/sheets';
/**
* This controller is responsible for changing the active worksheet when
diff --git a/packages/sheets/src/commands/commands/copy-worksheet.command.ts b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
index 3c81a573bd..c8e26f0a5c 100644
--- a/packages/sheets/src/commands/commands/copy-worksheet.command.ts
+++ b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
@@ -14,6 +14,12 @@
* limitations under the License.
*/
+import type { IAccessor, ICommand, IMutationInfo, Workbook } from '@univerjs/core';
+import type {
+ IInsertSheetMutationParams,
+ IRemoveSheetMutationParams,
+} from '../../basics/interfaces/mutation-interface';
+
import {
CommandType,
ICommandService,
@@ -23,16 +29,10 @@ import {
sequenceExecute,
Tools,
} from '@univerjs/core';
-import type { IAccessor, ICommand, IMutationInfo, Workbook } from '@univerjs/core';
-
import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { InsertSheetMutation, InsertSheetUndoMutationFactory } from '../mutations/insert-sheet.mutation';
import { RemoveSheetMutation } from '../mutations/remove-sheet.mutation';
import { getSheetCommandTarget } from './utils/target-util';
-import type {
- IInsertSheetMutationParams,
- IRemoveSheetMutationParams,
-} from '../../basics/interfaces/mutation-interface';
export interface ICopySheetCommandParams {
unitId?: string;
diff --git a/packages/sheets/src/commands/commands/insert-row-col.command.ts b/packages/sheets/src/commands/commands/insert-row-col.command.ts
index f2ce727891..8e515d14c7 100644
--- a/packages/sheets/src/commands/commands/insert-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/insert-row-col.command.ts
@@ -14,6 +14,14 @@
* limitations under the License.
*/
+import type { IAccessor, ICellData, ICommand, IMutationInfo, IObjectMatrixPrimitiveType, IRange } from '@univerjs/core';
+import type {
+ IInsertColMutationParams,
+ IInsertRowMutationParams,
+ IRemoveColMutationParams,
+ IRemoveRowsMutationParams,
+} from '../../basics/interfaces/mutation-interface';
+
import {
BooleanNumber,
CommandType,
@@ -24,8 +32,6 @@ import {
RANGE_TYPE,
sequenceExecute,
} from '@univerjs/core';
-import type { IAccessor, ICellData, ICommand, IMutationInfo, IObjectMatrixPrimitiveType, IRange } from '@univerjs/core';
-
import { SheetsSelectionsService } from '../../services/selections/selection-manager.service';
import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import {
@@ -38,12 +44,6 @@ import { RemoveColMutation, RemoveRowMutation } from '../mutations/remove-row-co
import { SetRangeValuesMutation } from '../mutations/set-range-values.mutation';
import { copyRangeStyles, followSelectionOperation } from './utils/selection-utils';
import { getSheetCommandTarget } from './utils/target-util';
-import type {
- IInsertColMutationParams,
- IInsertRowMutationParams,
- IRemoveColMutationParams,
- IRemoveRowsMutationParams,
-} from '../../basics/interfaces/mutation-interface';
export interface IInsertRowCommandParams {
unitId: string;
diff --git a/packages/sheets/src/commands/commands/set-range-values.command.ts b/packages/sheets/src/commands/commands/set-range-values.command.ts
index 7bace61bb3..37e1457b50 100644
--- a/packages/sheets/src/commands/commands/set-range-values.command.ts
+++ b/packages/sheets/src/commands/commands/set-range-values.command.ts
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+import type { IAccessor, ICellData, ICommand, IObjectMatrixPrimitiveType, IRange } from '@univerjs/core';
+import type { ISheetCommandSharedParams } from '../utils/interface';
+
import {
CommandType,
ICommandService,
@@ -25,15 +28,12 @@ import {
sequenceExecute,
Tools,
} from '@univerjs/core';
-import type { IAccessor, ICellData, ICommand, IObjectMatrixPrimitiveType, IRange } from '@univerjs/core';
-
import { WorksheetEditPermission } from '../../services/permission/permission-point';
import { SheetsSelectionsService } from '../../services/selections/selection-manager.service';
import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation';
import { followSelectionOperation } from './utils/selection-utils';
import { getSheetCommandTarget } from './utils/target-util';
-import type { ISheetCommandSharedParams } from '../utils/interface';
export interface ISetRangeValuesCommandParams extends Partial<ISheetCommandSharedParams> {
range?: IRange;
diff --git a/packages/sheets/src/commands/commands/utils/selection-utils.ts b/packages/sheets/src/commands/commands/utils/selection-utils.ts
index 21f842247e..3af143f252 100644
--- a/packages/sheets/src/commands/commands/utils/selection-utils.ts
+++ b/packages/sheets/src/commands/commands/utils/selection-utils.ts
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-import { RANGE_TYPE, Rectangle, selectionToArray } from '@univerjs/core';
import type { ICellData, IObjectMatrixPrimitiveType, IRange, ISelectionCell, Nullable, Workbook, Worksheet } from '@univerjs/core';
-
-import { SetSelectionsOperation } from '../../operations/selection.operation';
import type { ISelectionWithStyle } from '../../../basics/selection';
+
import type { ISetSelectionsOperationParams } from '../../operations/selection.operation';
+import { RANGE_TYPE, Rectangle, selectionToArray } from '@univerjs/core';
+import { SetSelectionsOperation } from '../../operations/selection.operation';
export interface IExpandParams {
left?: boolean;
diff --git a/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts b/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts
index b7972aaa6b..303b2ac07f 100644
--- a/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts
+++ b/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts
@@ -15,11 +15,11 @@
*/
import { createInterceptorKey } from '@univerjs/core';
-import type { ICellDataForSheetInterceptor, ICellInterceptor } from '@univerjs/core';
+import type { ICellData, ICellDataForSheetInterceptor, ICellInterceptor, Nullable } from '@univerjs/core';
import type { ISheetLocation, ISheetRowLocation } from './utils/interceptor';
-const CELL_CONTENT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('CELL_CONTENT') as ICellInterceptor<ICellDataForSheetInterceptor, ISheetLocation>;
+const CELL_CONTENT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation & { rawData: Nullable<ICellData> }>('CELL_CONTENT') as ICellInterceptor<ICellDataForSheetInterceptor, ISheetLocation & { rawData: Nullable<ICellData> }>;
const ROW_FILTERED = createInterceptorKey<boolean, ISheetRowLocation>('ROW_FILTERED');
export const INTERCEPTOR_POINT = {
diff --git a/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts
index a211e1dec0..f82229846e 100644
--- a/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts
+++ b/packages/sheets/src/services/sheet-interceptor/sheet-interceptor.service.ts
@@ -240,8 +240,9 @@ export class SheetInterceptorService extends Disposable {
sheetDisposables.add(viewModel.registerCellContentInterceptor({
getCell(row: number, col: number, effect: InterceptorEffectEnum): Nullable<ICellData> {
+ const rawData = worksheet.getCellRaw(row, col);
return sheetInterceptorService.fetchThroughInterceptors(INTERCEPTOR_POINT.CELL_CONTENT, effect)(
- worksheet.getCellRaw(row, col),
+ rawData,
{
unitId,
subUnitId,
@@ -249,6 +250,7 @@ export class SheetInterceptorService extends Disposable {
col,
worksheet,
workbook,
+ rawData,
}
);
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 55b2880ff4..25c2a7b1f4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1896,6 +1896,9 @@ importers:
packages/sheets-data-validation:
dependencies:
+ '@flatten-js/interval-tree':
+ specifier: ^1.1.3
+ version: 1.1.3
'@univerjs/core':
specifier: workspace:*
version: link:../core
@@ -4063,6 +4066,9 @@ packages:
resolution: {integrity: sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
+ '@flatten-js/[email protected]':
+ resolution: {integrity: sha512-xhFWUBoHJFF77cJO1D6REjdgJEMRf2Y2Z+eKEPav8evGKcLSnj1ud5pLXQSbGuxF3VSvT1rWhMfVpXEKJLTL+A==}
+
'@floating-ui/[email protected]':
resolution: {integrity: sha512-a4IowK4QkXl4SCWTGUR0INAfEOX3wtsYw3rKK5InQEHMGObkR8Xk44qYQD9P4r6HHw0iIfK6GUKECmY8sTkqRA==}
@@ -11503,6 +11509,8 @@ snapshots:
dependencies:
levn: 0.4.1
+ '@flatten-js/[email protected]': {}
+
'@floating-ui/[email protected]':
dependencies:
'@floating-ui/utils': 0.2.7