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(sheets-data-validation): date picker can't input by type when errorStyle is STOP (#3237)
zhangw99cfb4be73e7
diff --git a/examples/src/data/sheets/demo/default-workbook-data-demo.ts b/examples/src/data/sheets/demo/default-workbook-data-demo.tsindex 78da31be40..c23deaf926 100644--- a/examples/src/data/sheets/demo/default-workbook-data-demo.ts+++ b/examples/src/data/sheets/demo/default-workbook-data-demo.ts@@ -128,7 +128,7 @@ const dataValidation: IDataValidationRule[] = [operator: DataValidationOperator.LESS_THAN_OR_EQUAL,formula1: '2024/04/10',formula2: '2024/10/10',- // errorStyle: DataValidationErrorStyle.STOP,+ errorStyle: DataValidationErrorStyle.STOP,},{uid: 'xxx-2',diff --git a/packages/core/src/types/const/const.ts b/packages/core/src/types/const/const.tsindex febd7f5a07..26c7e3d7cd 100644--- a/packages/core/src/types/const/const.ts+++ b/packages/core/src/types/const/const.ts@@ -163,3 +163,8 @@ export const DEFAULT_SLIDE = {height: 300,},};++/**+ * Univer internal key on cellData.custom to save some internal values+ */+export const UNIVER_INTERNAL = '__univer_internal__';diff --git a/packages/sheets-data-validation/src/controllers/dv-reject-input.controller.ts b/packages/sheets-data-validation/src/controllers/dv-reject-input.controller.tsindex 8ca53c4c1d..345641015b 100644--- a/packages/sheets-data-validation/src/controllers/dv-reject-input.controller.ts+++ b/packages/sheets-data-validation/src/controllers/dv-reject-input.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { DataValidationErrorStyle, Disposable, Inject, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';+import { DataValidationErrorStyle, Disposable, Inject, LifecycleStages, LocaleService, OnLifecycle, UNIVER_INTERNAL } from '@univerjs/core';import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';import { IEditorBridgeService } from '@univerjs/sheets-ui';import { IDialogService } from '@univerjs/ui';@@ -58,7 +58,7 @@ export class DataValidationRejectInputController extends Disposable {const success = await validator.validator({value: getCellValueOrigin(cell),- interceptValue: getCellValueOrigin(cell),+ interceptValue: getCellValueOrigin(cell?.custom?.[UNIVER_INTERNAL]?.origin ?? cell),row,column: col,unitId,diff --git a/packages/sheets-data-validation/src/validators/date-validator.ts b/packages/sheets-data-validation/src/validators/date-validator.tsindex a32ba23ad9..3edf6fd62f 100644--- a/packages/sheets-data-validation/src/validators/date-validator.ts+++ b/packages/sheets-data-validation/src/validators/date-validator.ts@@ -86,7 +86,11 @@ export class DateValidator extends BaseDataValidator<number> {}override async isValidType(info: IValidatorCellInfo): Promise<boolean> {- const { interceptValue } = info;+ const { interceptValue, value } = info;+ if (typeof value === 'number' && typeof interceptValue === 'string') {+ return true;+ }+if (typeof interceptValue === 'string') {return Boolean(numfmt.parseDate(interceptValue));}diff --git a/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts b/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.tsindex b9dd5e0e95..423d3c9dc2 100644--- a/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts+++ b/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts@@ -15,7 +15,7 @@*/import type { ICellData, IDocumentData, Injector, Univer, Workbook } from '@univerjs/core';-import { CellValueType, IContextService, IResourceLoaderService, LocaleService, LocaleType, Tools } from '@univerjs/core';+import { CellValueType, IContextService, IResourceLoaderService, LocaleService, LocaleType, Tools, UNIVER_INTERNAL } from '@univerjs/core';import { LexerTreeBuilder } from '@univerjs/engine-formula';import { SpreadsheetSkeleton } from '@univerjs/engine-render';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -149,7 +149,18 @@ describe('Test EndEditController', () => {};const cellData = getCellDataByInputCell(cell, inputCell);- expect(cellData).toEqual({ v: '2', t: CellValueType.NUMBER, f: null, si: null, p: null });+ const target = { v: '2', t: CellValueType.NUMBER, f: null, si: null, p: null };++ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });});it('Rich text cell', () => {const cell = {@@ -160,7 +171,17 @@ describe('Test EndEditController', () => {};const cellData = getCellDataByInputCell(cell, inputCell);- expect(cellData).toEqual({ v: null, f: null, si: null, p: richTextDemo });+ const target = { v: null, f: null, si: null, p: richTextDemo };+ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });});it('Formula cell', () => {const cell = {@@ -171,7 +192,17 @@ describe('Test EndEditController', () => {};const cellData = getCellDataByInputCell(cell, inputCell);- expect(cellData).toEqual({ v: null, f: '=SUM(1)', si: null, p: null, t: undefined });+ const target = { v: null, f: '=SUM(1)', si: null, p: null, t: undefined };+ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });});it('Clear formula cell', () => {const cell = {@@ -185,7 +216,17 @@ describe('Test EndEditController', () => {};const cellData = getCellDataByInputCell(cell, inputCell);- expect(cellData).toEqual({ v: '', f: null, si: null, p: null, t: undefined });+ const target = { v: '', f: null, si: null, p: null, t: undefined };+ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });});it('Clear formula cell with rich text', () => {@@ -200,7 +241,17 @@ describe('Test EndEditController', () => {};const cellData = getCellDataByInputCell(cell, inputCell);- expect(cellData).toEqual({ v: null, f: null, si: null, p: richTextDemo, t: undefined });+ const target = { v: null, f: null, si: null, p: richTextDemo, t: undefined };+ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });});it('Input force string, normal string', () => {@@ -209,13 +260,43 @@ describe('Test EndEditController', () => {};let cellData = getCellDataByInputCell(cell, { v: "'test" });- expect(cellData).toEqual({ v: 'test', t: CellValueType.FORCE_STRING, f: null, si: null, p: null });+ let target = { v: 'test', t: CellValueType.FORCE_STRING, f: null, si: null, p: null };+ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });cellData = getCellDataByInputCell(cell, { v: "'1" });- expect(cellData).toEqual({ v: '1', t: CellValueType.FORCE_STRING, f: null, si: null, p: null });+ target = { v: '1', t: CellValueType.FORCE_STRING, f: null, si: null, p: null };+ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });cellData = getCellDataByInputCell(cell, { v: "'=SUM" });- expect(cellData).toEqual({ v: '=SUM', t: CellValueType.FORCE_STRING, f: null, si: null, p: null });+ target = { v: '=SUM', t: CellValueType.FORCE_STRING, f: null, si: null, p: null };+ expect(cellData).toEqual({+ ...target,+ custom: {+ [UNIVER_INTERNAL]: {+ origin: {+ ...target,+ },+ },+ },+ });});it('Function normalizeString', () => {diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.tsindex 8fba932987..42f9e966c9 100644--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts@@ -37,6 +37,7 @@ import {numfmt,toDisposable,Tools,+ UNIVER_INTERNAL,UniverInstanceType,VerticalAlign,WrapStrategy,@@ -905,6 +906,10 @@ export class EditingRenderController extends Disposable implements IRenderModuleconst finalCell = await this._editorBridgeService.interceptor.fetchThroughInterceptors(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT_ASYNC)(Promise.resolve(cell), context);+ // remove temp value+ if (finalCell?.custom?.[UNIVER_INTERNAL]?.origin) {+ finalCell.custom[UNIVER_INTERNAL] = null;+ }this._commandService.executeCommand(SetRangeValuesCommand.id, {subUnitId: sheetId,@@ -1110,6 +1115,12 @@ export function getCellDataByInput(}}+ cellData.custom = {+ [UNIVER_INTERNAL]: {+ origin: { ...cellData },+ },+ };+return cellData;}