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
fix: fix some issues with sheets-table (#5987)
wpxp123456580efc87fcfc
diff --git a/packages/core/src/shared/tools.ts b/packages/core/src/shared/tools.tsindex b92b565445..1c49e4c1c7 100644--- a/packages/core/src/shared/tools.ts+++ b/packages/core/src/shared/tools.ts@@ -641,3 +641,14 @@ export const isNodeEnv = () => {// eslint-disable-next-line node/prefer-global/processreturn typeof process !== 'undefined' && process.versions != null && process.versions.node != null;};++/**+ * Converts a wildcard pattern with ? and * to a regular expression.+ * @param {string} wildChar - The wildcard string containing ? and *+ * @returns {RegExp} The generated regular expression+ */+export function createREGEXFromWildChar(wildChar: string): RegExp {+ const escaped = wildChar.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const regexpStr = escaped.replace(/\\\*/g, '.*').replace(/\\\?/g, '.');+ return new RegExp(`^${regexpStr}$`, 'i');+}diff --git a/packages/sheets-filter/src/models/custom-filters.ts b/packages/sheets-filter/src/models/custom-filters.tsindex 5f14e60b51..69f11e065f 100644--- a/packages/sheets-filter/src/models/custom-filters.ts+++ b/packages/sheets-filter/src/models/custom-filters.ts@@ -15,7 +15,7 @@*/import type { CellValue, Nullable } from '@univerjs/core';-import { isNumeric } from '@univerjs/core';+import { createREGEXFromWildChar, isNumeric } from '@univerjs/core';import { CustomFilterOperator } from './types';export interface IFilterFn<P extends unknown[]> {@@ -190,9 +190,3 @@ function isWildCardString(str: string | number): boolean {return str.indexOf('*') !== -1 || str.indexOf('?') !== -1;}--function createREGEXFromWildChar(wildChar: string): RegExp {- // only '*' and '?' is supported- const regexpStr = wildChar.replace(/[.+^${}()|[\]\\]/g, '\\$&').replaceAll('?', '.').replace(/[*]/g, '.$&');- return new RegExp(`^${regexpStr}$`);-}diff --git a/packages/sheets-table/src/controllers/table-filter.controller.ts b/packages/sheets-table/src/controllers/table-filter.controller.tsindex 9371dda3a1..7453634027 100644--- a/packages/sheets-table/src/controllers/table-filter.controller.ts+++ b/packages/sheets-table/src/controllers/table-filter.controller.ts@@ -18,7 +18,7 @@ import type { Workbook } from '@univerjs/core';import type { Subscription } from 'rxjs';import { Disposable, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';-import { getSheetCommandTarget, INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';+import { getSheetCommandTarget, INTERCEPTOR_POINT, SheetInterceptorService, ZebraCrossingCacheController } from '@univerjs/sheets';import { BehaviorSubject, filter, switchMap } from 'rxjs';import { TableManager } from '../model/table-manager';@@ -30,7 +30,8 @@ export class TableFilterController extends Disposable {constructor(@Inject(TableManager) private _tableManager: TableManager,@Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,- @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService+ @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService,+ @Inject(ZebraCrossingCacheController) private readonly _zebraCrossingCacheController: ZebraCrossingCacheController) {super();this.registerFilterChangeEvent();@@ -112,6 +113,8 @@ export class TableFilterController extends Disposable {this.tableFilteredOutRows.add(row);}});++ this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, subUnitId);}));}diff --git a/packages/sheets-table/src/model/filter-util/text-filter-util.ts b/packages/sheets-table/src/model/filter-util/text-filter-util.tsindex c667c021b7..99df1cebf0 100644--- a/packages/sheets-table/src/model/filter-util/text-filter-util.ts+++ b/packages/sheets-table/src/model/filter-util/text-filter-util.ts@@ -15,46 +15,36 @@*/import type { ITableStringFilterInfo } from '../../types/type';+import { createREGEXFromWildChar } from '@univerjs/core';import { TableStringCompareTypeEnum } from '../../types/enum';-/**- * Converts a pattern with ? and * to a regular expression.- * @param {string} pattern - The pattern to convert.- * @returns {RegExp} The regular expression.- */-const patternToRegExp = (pattern: string): RegExp => {- const escapedPattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');- const regexPattern = escapedPattern.replace(/\\\*/g, '.*').replace(/\\\?/g, '.');- return new RegExp(`^${regexPattern}$`);-};-export const textEqual = (compareValue: string, expectedValue: string) => {- const regex = patternToRegExp(expectedValue);+ const regex = createREGEXFromWildChar(expectedValue);return regex.test(compareValue);};export const textNotEqual = (compareValue: string, expectedValue: string) => {- const regex = patternToRegExp(expectedValue);+ const regex = createREGEXFromWildChar(expectedValue);return !regex.test(compareValue);};export const textContain = (compareValue: string, expectedValue: string) => {- const regex = patternToRegExp(`*${expectedValue}*`);+ const regex = createREGEXFromWildChar(`*${expectedValue}*`);return regex.test(compareValue);};export const textNotContain = (compareValue: string, expectedValue: string) => {- const regex = patternToRegExp(`*${expectedValue}*`);+ const regex = createREGEXFromWildChar(`*${expectedValue}*`);return !regex.test(compareValue);};export const textStartWith = (compareValue: string, expectedValue: string) => {- const regex = patternToRegExp(`${expectedValue}*`);+ const regex = createREGEXFromWildChar(`${expectedValue}*`);return regex.test(compareValue);};export const textEndWith = (compareValue: string, expectedValue: string) => {- const regex = patternToRegExp(`*${expectedValue}`);+ const regex = createREGEXFromWildChar(`*${expectedValue}`);return regex.test(compareValue);};diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.tsindex caeeb09fc6..26d306cb7f 100644--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts@@ -626,6 +626,9 @@ export class EditingRenderController extends Disposable {return true;}+ // Remove the same style attributes that have been set by composed style in the cell data.+ this._removeComposedCellStyleInCellData(cellData, worksheet.getComposedCellStyle(row, column));+const finalCell = this._sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, cellData) as ICellData;if (Tools.diffValue(cleanCellDataObject(finalCell), cleanCellDataObject(worksheet.getCellRaw(row, column)))) {return true;@@ -660,6 +663,20 @@ export class EditingRenderController extends Disposable {return true;}+ private _removeComposedCellStyleInCellData(cellData: ICellData, composedStyle: IStyleData) {+ if (!cellData.s || typeof cellData.s === 'string') {+ return;+ }++ const keys = Object.keys(cellData.s);++ for (const key of keys) {+ if (composedStyle[key as keyof IStyleData] !== undefined && Tools.diffValue(cellData.s[key as keyof IStyleData], composedStyle[key as keyof IStyleData])) {+ delete cellData.s[key as keyof IStyleData];+ }+ }+ }+private _exitInput(param: IEditorBridgeServiceVisibleParam) {this._contextService.setContextValue(FOCUSING_EDITOR_INPUT_FORMULA, false);this._contextService.setContextValue(EDITOR_ACTIVATED, false);diff --git a/packages/sheets/src/model/range-theme-model.ts b/packages/sheets/src/model/range-theme-model.tsindex c406161704..cf08203370 100644--- a/packages/sheets/src/model/range-theme-model.ts+++ b/packages/sheets/src/model/range-theme-model.ts@@ -125,6 +125,7 @@ export class SheetRangeThemeModel extends Disposable {public refreshSheetRowVisibleFuncSet(unitId: string, subUnitId: string) {const set = this._getSheetRowVisibleFuncSet(unitId, subUnitId);+ set.clear();const workbook = this._univerInstanceService.getUnit<Workbook>(unitId);if (workbook) {const sheet = workbook.getSheetBySheetId(subUnitId);