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.

feat(sheets): support data validation (#1676)

zhangw9961b3243c33
diff --git a/examples/package.json b/examples/package.json
index ce079e7c40..d4688a2749 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -11,6 +11,7 @@
},
"dependencies": {
"@univerjs/core": "workspace:*",
+ "@univerjs/data-validation": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
@@ -23,6 +24,7 @@
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
"@univerjs/sheets-conditional-formatting-ui": "workspace:*",
+ "@univerjs/sheets-data-validation": "workspace:*",
"@univerjs/sheets-find-replace": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
diff --git a/examples/src/data/sheets/demo/default-workbook-data-demo.ts b/examples/src/data/sheets/demo/default-workbook-data-demo.ts
index 59bcef3d05..ae17bbdc70 100644
--- a/examples/src/data/sheets/demo/default-workbook-data-demo.ts
+++ b/examples/src/data/sheets/demo/default-workbook-data-demo.ts
@@ -15,8 +15,9 @@
*/
import type { IDocumentData, IWorkbookData } from '@univerjs/core';
-import { BooleanNumber, LocaleType } from '@univerjs/core';
+import { BooleanNumber, DataValidationErrorStyle, DataValidationOperator, DataValidationType, LocaleType } from '@univerjs/core';
+import { DATA_VALIDATION_PLUGIN_NAME } from '@univerjs/sheets-data-validation';
import { PAGE5_RICHTEXT_1 } from '../../slides/rich-text/page5-richtext1';
const richTextDemo: IDocumentData = {
@@ -100,6 +101,78 @@ const richTextDemo1: IDocumentData = {
},
};
+const dataValidation = [
+ {
+ uid: 'xxx-1',
+ type: DataValidationType.DECIMAL,
+ ranges: [{
+ startRow: 0,
+ endRow: 5,
+ startColumn: 0,
+ endColumn: 2,
+ }],
+ operator: DataValidationOperator.GREATER_THAN,
+ formula1: '111',
+ errorStyle: DataValidationErrorStyle.STOP,
+ },
+ {
+ uid: 'xxx-0',
+ type: DataValidationType.DATE,
+ ranges: [{
+ startRow: 0,
+ endRow: 5,
+ startColumn: 3,
+ endColumn: 5,
+ }],
+ operator: DataValidationOperator.GREATER_THAN,
+ formula1: '100',
+ errorStyle: DataValidationErrorStyle.STOP,
+ },
+ {
+ uid: 'xxx-2',
+ type: DataValidationType.CHECKBOX,
+ ranges: [{
+ startRow: 6,
+ endRow: 10,
+ startColumn: 0,
+ endColumn: 5,
+ }],
+ },
+ {
+ uid: 'xxx-3',
+ type: DataValidationType.LIST,
+ ranges: [{
+ startRow: 11,
+ endRow: 15,
+ startColumn: 0,
+ endColumn: 5,
+ }],
+ formula1: '1,2,3,hahaha',
+ },
+ {
+ uid: 'xxx-4',
+ type: DataValidationType.CUSTOM,
+ ranges: [{
+ startRow: 16,
+ endRow: 20,
+ startColumn: 0,
+ endColumn: 5,
+ }],
+ formula1: '=A1',
+ },
+ {
+ uid: 'xxx-5',
+ type: DataValidationType.LIST_MULTIPLE,
+ ranges: [{
+ startRow: 21,
+ endRow: 21,
+ startColumn: 0,
+ endColumn: 0,
+ }],
+ formula1: '1,2,3,4,5,哈哈哈哈',
+ },
+];
+
export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
id: 'workbook-01',
locale: LocaleType.ZH_CN,
@@ -13875,7 +13948,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
id: 'sheet-0011',
tabColor: '',
hidden: 0,
- rowCount: 1000000,
+ rowCount: 1000,
columnCount: 20,
zoomRatio: 1,
cellData: {
@@ -15147,9 +15220,11 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
21: {
0: {
s: 'u5otPe',
+ v: '1,2',
},
1: {
s: 'u5otPe',
+ v: '1,2,3',
},
2: {
s: 'u5otPe',
@@ -23303,6 +23378,14 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
// },
// },
},
+ resources: [
+ {
+ name: DATA_VALIDATION_PLUGIN_NAME,
+ data: JSON.stringify({
+ 'sheet-0011': dataValidation,
+ }),
+ },
+ ],
// namedRanges: [
// {
// namedRangeId: 'named-rang',
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.ts
index b262c2b3e5..7779002d71 100644
--- a/examples/src/sheets/main.ts
+++ b/examples/src/sheets/main.ts
@@ -30,6 +30,8 @@ import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
import { UniverUIPlugin } from '@univerjs/ui';
+import { UniverDataValidationPlugin } from '@univerjs/data-validation';
+import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';
import { SheetsConditionalFormattingUiPlugin } from '@univerjs/sheets-conditional-formatting-ui';
import { DebuggerPlugin } from '../plugins/debugger';
@@ -78,6 +80,11 @@ univer.registerPlugin(UniverRPCMainThreadPlugin, {
// find replace
univer.registerPlugin(UniverFindReplacePlugin);
+// univer.registerPlugin(UniverSheetsFindPlugin);
+
+// data validation
+univer.registerPlugin(UniverDataValidationPlugin);
+univer.registerPlugin(UniverSheetsDataValidationPlugin);
univer.registerPlugin(UniverSheetsFindReplacePlugin);
// create univer sheet instance
diff --git a/packages/core/src/common/equal.ts b/packages/core/src/common/equal.ts
new file mode 100644
index 0000000000..5d0c30e13d
--- /dev/null
+++ b/packages/core/src/common/equal.ts
@@ -0,0 +1,81 @@
+/**
+ * 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 { Rectangle } from '../shared/rectangle';
+import type { IRange, IUnitRange } from '../types/interfaces';
+
+/**
+ * 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.
+ */
+
+export const isRangesEqual = (oldRanges: IRange[], ranges: IRange[]) => {
+ return ranges.length === oldRanges.length && !oldRanges.some((oldRange) => ranges.some((range) => !Rectangle.equals(range, oldRange)));
+};
+
+export const isUnitRangesEqual = (oldRanges: IUnitRange[], ranges: IUnitRange[]) => {
+ return ranges.length === oldRanges.length && oldRanges.every((oldRange, i) => {
+ const current = ranges[i];
+ return current.unitId === oldRange.unitId && current.sheetId === oldRange.sheetId && Rectangle.equals(oldRange.range, current.range);
+ });
+};
+
+export function shallowEqual(objA: any, objB: any) {
+ if (Object.is(objA, objB)) {
+ return true;
+ }
+
+ if (typeof objA !== 'object' || !objA || typeof objB !== 'object' || !objB) {
+ return false;
+ }
+
+ const keysA = Object.keys(objA);
+ const keysB = Object.keys(objB);
+
+ if (keysA.length !== keysB.length) {
+ return false;
+ }
+
+ const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
+
+ // Test for A's keys different from B.
+ for (let idx = 0; idx < keysA.length; idx++) {
+ const key = keysA[idx];
+
+ if (!bHasOwnProperty(key)) {
+ return false;
+ }
+
+ const valueA = objA[key];
+ const valueB = objB[key];
+ if (valueA !== valueB) {
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index f68de6d8f1..e951ba69f2 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -16,6 +16,7 @@
import { installShims } from './common/shims';
+export { shallowEqual, isRangesEqual, isUnitRangesEqual } from './common/equal';
export * from './basics';
export { dedupe, remove, rotate, groupBy } from './common/array';
export {
@@ -151,4 +152,13 @@ export { getSheetBlocksFromSnapshot } from './services/snapshot/snapshot-transfo
export { isBlackColor, isWhiteColor } from './shared/color/color-kit';
export { cellToRange } from './shared/common';
+export type { IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleInfo, IDataValidationRuleOptions, ISheetDataValidationRule } from './types/interfaces/i-data-validation';
+export type { ICellCustomRender, ICellRenderContext } from './types/interfaces/i-cell-custom-render';
+
+export { DataValidationErrorStyle } from './types/enum/data-validation-error-style';
+export { DataValidationImeMode } from './types/enum/data-validation-ime-mode';
+export { DataValidationOperator } from './types/enum/data-validation-operator';
+export { DataValidationType } from './types/enum/data-validation-type';
+export { DataValidationStatus } from './types/enum/data-validation-status';
+
installShims();
diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.ts
index 67745cd6ae..0601d180bc 100644
--- a/packages/core/src/shared/common.ts
+++ b/packages/core/src/shared/common.ts
@@ -522,7 +522,16 @@ export function getDocsUpdateBody(model: IDocumentData, segmentId?: string) {
export function isValidRange(range: IRange): boolean {
const { startRow, endRow, startColumn, endColumn } = range;
- if (startRow < 0 || startColumn < 0 || endRow < 0 || endColumn < 0) {
+ if (
+ startRow < 0
+ || startColumn < 0
+ || endRow < 0
+ || endColumn < 0
+ || Number.isNaN(startRow)
+ || Number.isNaN(endRow)
+ || Number.isNaN(startColumn)
+ || Number.isNaN(endColumn)
+ ) {
return false;
}
diff --git a/packages/core/src/shared/index.ts b/packages/core/src/shared/index.ts
index c6203cef75..6101782b1b 100644
--- a/packages/core/src/shared/index.ts
+++ b/packages/core/src/shared/index.ts
@@ -37,3 +37,4 @@ export * from './sort-rules';
export * from './tools';
export * from './types';
export * from './debounce';
+export { queryObjectMatrix } from './object-matrix-query';
diff --git a/packages/core/src/shared/object-matrix-query.ts b/packages/core/src/shared/object-matrix-query.ts
new file mode 100644
index 0000000000..73fd7a04e2
--- /dev/null
+++ b/packages/core/src/shared/object-matrix-query.ts
@@ -0,0 +1,101 @@
+/**
+ * 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 type { Nullable } from 'vitest';
+import { Range } from '../sheets/range';
+import type { IRange } from '../types/interfaces';
+import type { ObjectMatrix } from './object-matrix';
+
+function maximalRectangle<T>(matrix: T[][], match: (val: T) => boolean) {
+ if (matrix.length === 0 || matrix[0].length === 0) return null;
+
+ const heights = new Array(matrix[0].length).fill(0);
+ let maxArea = 0;
+ let maxRect = null;
+
+ for (let row = 0; row < matrix.length; row++) {
+ for (let col = 0; col < matrix[0].length; col++) {
+ heights[col] = match(matrix[row][col]) ? heights[col] + 1 : 0;
+ }
+
+ const areaWithRect = largestRectangleArea(heights);
+ if (areaWithRect.area > maxArea) {
+ maxArea = areaWithRect.area;
+ // Adjust the rectangle's top row to the current row minus the height plus one
+ maxRect = {
+ startColumn: areaWithRect.start,
+ startRow: row - areaWithRect.height + 1,
+ endColumn: areaWithRect.end,
+ endRow: row,
+ };
+ }
+ }
+
+ return maxRect;
+}
+
+function largestRectangleArea(heights: number[]) {
+ const stack: number[] = [];
+ let maxArea = 0;
+ let maxRect = { area: 0, height: 0, start: 0, end: 0 };
+ let index = 0;
+
+ while (index < heights.length) {
+ if (stack.length === 0 || heights[index] >= heights[stack[stack.length - 1]]) {
+ stack.push(index++);
+ } else {
+ const height = heights[stack.pop()!];
+ const width = stack.length === 0 ? index : index - stack[stack.length - 1] - 1;
+ if (height * width > maxArea) {
+ maxArea = height * width;
+ maxRect = { area: maxArea, height, start: stack.length === 0 ? 0 : stack[stack.length - 1] + 1, end: index - 1 };
+ }
+ }
+ }
+
+ while (stack.length > 0) {
+ const height = heights[stack.pop()!];
+ const width = stack.length === 0 ? index : index - stack[stack.length - 1] - 1;
+ if (height * width > maxArea) {
+ maxArea = height * width;
+ maxRect = { area: maxArea, height, start: stack.length === 0 ? 0 : stack[stack.length - 1] + 1, end: index - 1 };
+ }
+ }
+
+ return maxRect;
+}
+
+function resetMatrix<T>(matrix: Nullable<T>[][], range: IRange) {
+ Range.foreach(range, (row, col) => {
+ matrix[row][col] = undefined;
+ });
+}
+
+export function queryObjectMatrix<T>(matrix: ObjectMatrix<T>, match: (value: T) => boolean) {
+ const arrayMatrix = matrix.toFullArray();
+ const results: IRange[] = [];
+ while (true) {
+ const rectangle = maximalRectangle(arrayMatrix, match);
+ if (!rectangle) {
+ break;
+ }
+
+ results.push(rectangle);
+ resetMatrix(arrayMatrix, rectangle);
+ }
+
+ return results;
+}
diff --git a/packages/core/src/shared/object-matrix.ts b/packages/core/src/shared/object-matrix.ts
index 89dd11a1b6..3bdc3803ea 100644
--- a/packages/core/src/shared/object-matrix.ts
+++ b/packages/core/src/shared/object-matrix.ts
@@ -557,6 +557,22 @@ export class ObjectMatrix<T> {
return array;
}
+ toFullArray(): T[][] {
+ const range = this.getRange();
+ const { endColumn, endRow } = range;
+ const array: T[][] = [];
+ for (let i = 0; i <= endRow; i++) {
+ const subArr = Array(endColumn + 1).fill(undefined);
+ array.push(subArr);
+ }
+
+ this.forValue((row, col, value) => {
+ array[row][col] = value;
+ });
+
+ return array;
+ }
+
/**
* @deprecated Use getMatrix as a substitute.
*/
diff --git a/packages/core/src/sheets/view-model.ts b/packages/core/src/sheets/view-model.ts
index 7f85c6f038..17f4327c6f 100644
--- a/packages/core/src/sheets/view-model.ts
+++ b/packages/core/src/sheets/view-model.ts
@@ -22,7 +22,7 @@ import { Disposable, toDisposable } from '../shared/lifecycle';
import type { ICellDataForSheetInterceptor } from '../types/interfaces/i-cell-data';
export interface ICellContentInterceptor {
- getCell(row: number, col: number): Nullable<ICellDataForSheetInterceptor>;
+ getCell: (row: number, col: number) => Nullable<ICellDataForSheetInterceptor>;
}
export interface IRowFilteredInterceptor {}
@@ -32,12 +32,12 @@ export interface IRowVisibleInterceptor {}
export interface IColVisibleInterceptor {}
export interface ISheetViewModel {
- registerCellContentInterceptor(interceptor: ICellContentInterceptor): IDisposable;
- registerRowFilteredInterceptor(interceptor: IRowFilteredInterceptor): IDisposable;
- registerRowVisibleInterceptor(interceptor: IRowVisibleInterceptor): IDisposable;
- registerColVisibleInterceptor(interceptor: IColVisibleInterceptor): IDisposable;
+ registerCellContentInterceptor: (interceptor: ICellContentInterceptor) => IDisposable;
+ registerRowFilteredInterceptor: (interceptor: IRowFilteredInterceptor) => IDisposable;
+ registerRowVisibleInterceptor: (interceptor: IRowVisibleInterceptor) => IDisposable;
+ registerColVisibleInterceptor: (interceptor: IColVisibleInterceptor) => IDisposable;
- getCell(row: number, col: number): Nullable<ICellDataForSheetInterceptor>;
+ getCell: (row: number, col: number) => Nullable<ICellDataForSheetInterceptor>;
}
/**
@@ -73,7 +73,6 @@ export class SheetViewModel extends Disposable implements ISheetViewModel {
if (this._cellContentInterceptors.includes(interceptor)) {
throw new Error('[SheetViewModel]: Interceptor already registered.');
}
-
this._cellContentInterceptors.push(interceptor);
return toDisposable(() => remove(this._cellContentInterceptors, interceptor));
}
diff --git a/packages/core/src/types/enum/data-validation-error-style.ts b/packages/core/src/types/enum/data-validation-error-style.ts
new file mode 100644
index 0000000000..befa6c3e18
--- /dev/null
+++ b/packages/core/src/types/enum/data-validation-error-style.ts
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+export enum DataValidationErrorStyle {
+ INFO,
+ STOP,
+ WARNING,
+}
diff --git a/packages/core/src/types/enum/data-validation-ime-mode.ts b/packages/core/src/types/enum/data-validation-ime-mode.ts
new file mode 100644
index 0000000000..a85677d30a
--- /dev/null
+++ b/packages/core/src/types/enum/data-validation-ime-mode.ts
@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+
+export enum DataValidationImeMode {
+ DISABLED,
+ FULL_ALPHA,
+ FULL_HANGUL,
+ FULL_KATAKANA,
+ HALF_ALPHA,
+ HALF_HANGUL,
+ HALF_KATAKANA,
+ HIRAGANA,
+ NO_CONTROL,
+ OFF,
+ ON,
+}
diff --git a/packages/core/src/types/enum/data-validation-operator.ts b/packages/core/src/types/enum/data-validation-operator.ts
new file mode 100644
index 0000000000..fc989b1ffc
--- /dev/null
+++ b/packages/core/src/types/enum/data-validation-operator.ts
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+
+export enum DataValidationOperator {
+ BETWEEN = 'between',
+ EQUAL = 'equal',
+ GREATER_THAN = 'greaterThan',
+ GREATER_THAN_OR_EQUAL = 'greaterThanOrEqual',
+ LESS_THAN = 'lessThan',
+ LESS_THAN_OR_EQUAL = 'lessThanOrEqual',
+ NOT_BETWEEN = 'notBetween',
+ NOT_EQUAL = 'notEqual',
+}
diff --git a/packages/core/src/types/enum/data-validation-render-mode.ts b/packages/core/src/types/enum/data-validation-render-mode.ts
new file mode 100644
index 0000000000..b06170f525
--- /dev/null
+++ b/packages/core/src/types/enum/data-validation-render-mode.ts
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+export enum DataValidationRenderMode {
+ TEXT = 0,
+ ARROW = 1,
+ CUSTOM = 2,
+}
diff --git a/packages/core/src/types/enum/data-validation-status.ts b/packages/core/src/types/enum/data-validation-status.ts
new file mode 100644
index 0000000000..71d23e1858
--- /dev/null
+++ b/packages/core/src/types/enum/data-validation-status.ts
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+export enum DataValidationStatus {
+ VALID = 'valid',
+ INVALID = 'invalid',
+ VALIDATING = 'validating',
+}
diff --git a/packages/core/src/types/enum/data-validation-type.ts b/packages/core/src/types/enum/data-validation-type.ts
new file mode 100644
index 0000000000..fe026a2924
--- /dev/null
+++ b/packages/core/src/types/enum/data-validation-type.ts
@@ -0,0 +1,37 @@
+/**
+ * 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.
+ */
+
+export enum DataValidationType {
+ /**
+ * custom formula
+ */
+ CUSTOM = 'custom',
+ LIST = 'list',
+ LIST_MULTIPLE = 'listMultiple',
+ NONE = 'none',
+ TEXT_LENGTH = 'textLength',
+ DATE = 'date',
+ TIME = 'time',
+ /**
+ * integer number
+ */
+ WHOLE = 'whole',
+ /**
+ * decimal number
+ */
+ DECIMAL = 'decimal',
+ CHECKBOX = 'checkbox',
+}
diff --git a/packages/core/src/types/interfaces/i-cell-custom-render.ts b/packages/core/src/types/interfaces/i-cell-custom-render.ts
new file mode 100644
index 0000000000..59ade66714
--- /dev/null
+++ b/packages/core/src/types/interfaces/i-cell-custom-render.ts
@@ -0,0 +1,42 @@
+/**
+ * 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 type { Nullable } from '../../shared';
+import type { ISelectionCellWithCoord } from './i-selection-data';
+import type { IStyleData } from './i-style-data';
+import type { ICellDataForSheetInterceptor } from './i-cell-data';
+
+export interface ICellRenderContext {
+ data: ICellDataForSheetInterceptor;
+ style: Nullable<IStyleData>;
+ primaryWithCoord: ISelectionCellWithCoord;
+ unitId?: string;
+ subUnitId: string;
+ row: number;
+ col: number;
+}
+
+/**
+ * @debt This shouldn't exist in core package.
+ */
+export interface ICellCustomRender {
+ drawWith(ctx: CanvasRenderingContext2D, info: ICellRenderContext, skeleton: any, spreadsheets: any): void;
+ zIndex?: number;
+ isHit?: (position: { x: number;y: number }, info: ICellRenderContext) => boolean;
+ onPointerDown?: (info: ICellRenderContext, evt: any) => void;
+ onPointerEnter?: (info: ICellRenderContext, evt: any) => void;
+ onPointerLeave?: (info: ICellRenderContext, evt: any) => void;
+}
diff --git a/packages/core/src/types/interfaces/i-cell-data.ts b/packages/core/src/types/interfaces/i-cell-data.ts
index 809ea390db..e2d940f2a6 100644
--- a/packages/core/src/types/interfaces/i-cell-data.ts
+++ b/packages/core/src/types/interfaces/i-cell-data.ts
@@ -16,8 +16,10 @@
import type { Nullable } from '../../shared/types';
import { CellValueType } from '../enum/text-style';
+import type { ICellCustomRender } from './i-cell-custom-render';
import type { IDocumentData } from './i-document-data';
import type { IStyleData } from './i-style-data';
+import type { ICellValidationData } from './i-cell-validation-data';
/**
* Cell value type
@@ -56,9 +58,25 @@ export interface ICellData {
si?: Nullable<string>;
}
+export interface ICellMarksStyle {
+ color: string;
+ size: number;
+}
+
+export interface ICellMarks {
+ tl?: ICellMarksStyle;
+ tr?: ICellMarksStyle;
+ bl?: ICellMarksStyle;
+ br?: ICellMarksStyle;
+}
+
export interface ICellDataForSheetInterceptor extends ICellData {
interceptorStyle?: Nullable<IStyleData>;
isInArrayFormulaRange?: Nullable<boolean>;
+ dataValidation?: Nullable<ICellValidationData>;
+ markers?: ICellMarks;
+ customRender?: Nullable<ICellCustomRender[]>;
+ interceptorAutoHeight?: number;
}
export function isICellData(value: any): value is ICellData {
diff --git a/packages/core/src/types/interfaces/i-cell-validation-data.ts b/packages/core/src/types/interfaces/i-cell-validation-data.ts
new file mode 100644
index 0000000000..6a91445542
--- /dev/null
+++ b/packages/core/src/types/interfaces/i-cell-validation-data.ts
@@ -0,0 +1,25 @@
+/**
+ * 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 type { DataValidationStatus } from '../enum/data-validation-status';
+import type { IDataValidationRule } from './i-data-validation';
+
+export interface ICellValidationData {
+ ruleId: string;
+ validStatus: DataValidationStatus;
+ rule: IDataValidationRule;
+ validator: any;
+}
diff --git a/packages/core/src/types/interfaces/i-data-validation.ts b/packages/core/src/types/interfaces/i-data-validation.ts
new file mode 100644
index 0000000000..7df6c56ab5
--- /dev/null
+++ b/packages/core/src/types/interfaces/i-data-validation.ts
@@ -0,0 +1,65 @@
+/**
+ * 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 type { DataValidationOperator } from '../enum/data-validation-operator';
+import type { DataValidationType } from '../enum/data-validation-type';
+import type { DataValidationImeMode } from '../enum/data-validation-ime-mode';
+import type { DataValidationErrorStyle } from '../enum/data-validation-error-style';
+import type { DataValidationRenderMode } from '../enum/data-validation-render-mode';
+import type { IRange } from './i-range';
+
+export interface IDataValidationRuleBase {
+ type: DataValidationType;
+ allowBlank?: boolean;
+ formula1?: string;
+ formula2?: string;
+ operator?: DataValidationOperator;
+}
+
+export interface IDataValidationRuleOptions {
+ error?: string;
+ errorStyle?: DataValidationErrorStyle;
+ errorTitle?: string;
+ imeMode?: DataValidationImeMode;
+ prompt?: string;
+ promptTitle?: string;
+ showDropDown?: boolean;
+ showErrorMessage?: boolean;
+ showInputMessage?: boolean;
+ /**
+ * cell render mode of data validation
+ */
+ renderMode?: DataValidationRenderMode;
+}
+
+export interface IDataValidationRule extends IDataValidationRuleBase, IDataValidationRuleOptions {
+ uid: string;
+ /**
+ * @debt should using specific type cover sheet、doc、slide range type
+ */
+ ranges: any;
+
+}
+
+export interface ISheetDataValidationRule extends IDataValidationRule {
+ ranges: IRange[];
+}
+
+export interface IDataValidationRuleInfo {
+ rule: IDataValidationRule;
+ unitId: string;
+ subUnitId: string;
+}
diff --git a/packages/data-validation/README-zh.md b/packages/data-validation/README-zh.md
new file mode 100644
index 0000000000..0b95931c82
--- /dev/null
+++ b/packages/data-validation/README-zh.md
@@ -0,0 +1,24 @@
+# @univerjs/data-validation
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/data-validation)](https://npmjs.org/packages/@univerjs/data-validation)
+[![license](https://img.shields.io/npm/l/@univerjs/data-validation)](https://img.shields.io/npm/l/@univerjs/data-validation)
+
+## 简介
+
+> `@univerjs/data-validation` 提供了基础的数据验证功能.
+
+## 使用指南
+
+### 安装
+
+```shell
+npm i @univerjs/data-validation
+```
+
+### 注册插件
+
+```typescript
+import { UniverDataValidationPlugin } from '@univerjs/data-validation';
+
+univer.registerPlugin(UniverDataValidationPlugin);
+```
\ No newline at end of file
diff --git a/packages/data-validation/README.md b/packages/data-validation/README.md
new file mode 100644
index 0000000000..9c2de59048
--- /dev/null
+++ b/packages/data-validation/README.md
@@ -0,0 +1,24 @@
+# @univerjs/data-validation
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/data-validation)](https://npmjs.org/packages/@univerjs/data-validation)
+[![license](https://img.shields.io/npm/l/@univerjs/data-validation)](https://img.shields.io/npm/l/@univerjs/data-validation)
+
+## Introduction
+
+> `@univerjs/data-validation` provides Univer Sheet with basic capabilities for data validation computation.
+
+## Usage
+
+### Installation
+
+```shell
+npm i @univerjs/data-validation
+```
+
+### Register the plugin
+
+```typescript
+import { UniverDataValidationPlugin } from '@univerjs/data-validation';
+
+univer.registerPlugin(UniverDataValidationPlugin);
+```
\ No newline at end of file
diff --git a/packages/data-validation/package.json b/packages/data-validation/package.json
new file mode 100644
index 0000000000..f15776c228
--- /dev/null
+++ b/packages/data-validation/package.json
@@ -0,0 +1,76 @@
+{
+ "name": "@univerjs/data-validation",
+ "version": "0.1.5",
+ "private": false,
+ "description": "",
+ "author": "univer.ai",
+ "license": "",
+ "keywords": [],
+ "exports": {
+ ".": "./src/index.ts",
+ "./*": "./src/*"
+ },
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/esm/index.js",
+ "types": "./lib/types/index.d.ts",
+ "publishConfig": {
+ "access": "public",
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/es/index.js",
+ "exports": {
+ ".": {
+ "import": "./lib/es/index.js",
+ "require": "./lib/cjs/index.js",
+ "types": "./lib/types/index.d.ts"
+ },
+ "./*": {
+ "import": "./lib/es/*",
+ "require": "./lib/cjs/*",
+ "types": "./lib/types/index.d.ts"
+ }
+ }
+ },
+ "directories": {
+ "lib": "lib"
+ },
+ "files": [
+ "lib"
+ ],
+ "scripts": {
+ "dev": "vite",
+ "test": "vitest run",
+ "test:watch": "vitest",
+ "coverage": "vitest run --coverage",
+ "build": "tsc && vite build"
+ },
+ "peerDependencies": {
+ "@univerjs/core": "*",
+ "@wendellhu/redi": "^0.13.0",
+ "rxjs": ">=7.0.0"
+ },
+ "dependencies": {
+ "@univerjs/core": "*",
+ "@wendellhu/redi": "^0.13.0",
+ "dayjs": "^1.11.10",
+ "rxjs": "^7.8.1"
+ },
+ "devDependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/design": "workspace:*",
+ "@univerjs/docs": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
+ "@univerjs/engine-numfmt": "workspace:*",
+ "@univerjs/engine-render": "workspace:*",
+ "@univerjs/network": "workspace:*",
+ "@univerjs/rpc": "workspace:*",
+ "@univerjs/shared": "workspace:*",
+ "@univerjs/sheets": "workspace:*",
+ "@univerjs/sheets-formula": "workspace:*",
+ "@vitest/coverage-istanbul": "^1.2.1",
+ "typescript": "^5.3.3",
+ "vite": "^5.0.11",
+ "vite-plugin-dts": "^3.7.1",
+ "vite-plugin-externals": "^0.6.2",
+ "vitest": "^1.2.1"
+ }
+}
diff --git a/packages/data-validation/src/commands/commands/data-validation.command.ts b/packages/data-validation/src/commands/commands/data-validation.command.ts
new file mode 100644
index 0000000000..170df816fc
--- /dev/null
+++ b/packages/data-validation/src/commands/commands/data-validation.command.ts
@@ -0,0 +1,327 @@
+/**
+ * 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 { CommandType, ICommandService, IUndoRedoService } from '@univerjs/core';
+import type { ICommand, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IMutationInfo, IRange, ISheetDataValidationRule } from '@univerjs/core';
+import type { Injector } from '@wendellhu/redi';
+import type { ISheetCommandSharedParams } from '@univerjs/sheets';
+import type { IAddDataValidationMutationParams, IRemoveDataValidationMutationParams, IUpdateDataValidationMutationParams } from '../mutations/data-validation.mutation';
+import { AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation } from '../mutations/data-validation.mutation';
+import { DataValidatorRegistryService } from '../../services/data-validator-registry.service';
+import { DataValidationModel } from '../../models/data-validation-model';
+import { getRuleOptions, getRuleSetting } from '../../common/util';
+import { UpdateRuleType } from '../../types/enum/update-rule-type';
+
+export interface IAddDataValidationCommandParams extends ISheetCommandSharedParams {
+ rule: Omit<IDataValidationRule, 'ranges'> & {
+ range: IRange;
+ };
+ index?: number;
+}
+
+export const AddDataValidationCommand: ICommand<IAddDataValidationCommandParams> = {
+ type: CommandType.COMMAND,
+ id: 'data-validation.command.addRule',
+ async handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const { rule, unitId, subUnitId } = params;
+ const commandService = accessor.get(ICommandService);
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const mutationParams: IAddDataValidationMutationParams = {
+ ...params,
+ rule: {
+ ...params.rule,
+ ranges: [params.rule.range],
+ },
+ };
+ const redoMutations: IMutationInfo[] = [{
+ id: AddDataValidationMutation.id,
+ params: mutationParams,
+ }];
+
+ const undoMutations: IMutationInfo[] = [{
+ id: RemoveDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ ruleId: rule.uid,
+ },
+ }];
+ undoRedoService.pushUndoRedo({
+ unitID: unitId,
+ redoMutations,
+ undoMutations,
+ });
+
+ await commandService.executeCommand(AddDataValidationMutation.id, mutationParams);
+ return true;
+ },
+};
+
+export interface IRemoveDataValidationCommandParams extends ISheetCommandSharedParams {
+ ruleId: string;
+}
+
+export const removeDataValidationUndoFactory = (accessor: Injector, redoParams: IRemoveDataValidationMutationParams) => {
+ const dataValidationModel = accessor.get(DataValidationModel);
+ const { unitId, subUnitId, ruleId } = redoParams;
+ if (Array.isArray(ruleId)) {
+ const rules = ruleId.map((id) => dataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean) as ISheetDataValidationRule[];
+ return [{
+ id: AddDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ rule: rules,
+ } as IAddDataValidationMutationParams,
+ }];
+ }
+
+ const undoMutations: IMutationInfo[] = [{
+ id: AddDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ rule: {
+ ...dataValidationModel.getRuleById(unitId, subUnitId, ruleId),
+ },
+ index: dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId),
+ } as IAddDataValidationMutationParams,
+ }];
+
+ return undoMutations;
+};
+
+export const RemoveDataValidationCommand: ICommand<IRemoveDataValidationCommandParams> = {
+ type: CommandType.COMMAND,
+ id: 'data-validation.command.removeRule',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const { unitId, subUnitId, ruleId } = params;
+ const commandService = accessor.get(ICommandService);
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const dataValidationModel = accessor.get(DataValidationModel);
+
+ const redoMutations: IMutationInfo[] = [{
+ id: RemoveDataValidationMutation.id,
+ params,
+ }];
+ const undoMutations: IMutationInfo[] = [{
+ id: AddDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ rule: {
+ ...dataValidationModel.getRuleById(unitId, subUnitId, ruleId),
+ },
+ index: dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId),
+ } as IAddDataValidationMutationParams,
+ }];
+
+ undoRedoService.pushUndoRedo({
+ undoMutations,
+ redoMutations,
+ unitID: params.unitId,
+ });
+
+ commandService.executeCommand(RemoveDataValidationMutation.id, params);
+ return true;
+ },
+};
+
+export interface IUpdateDataValidationOptionsCommandParams extends ISheetCommandSharedParams {
+ ruleId: string;
+ options: IDataValidationRuleOptions;
+}
+
+export const UpdateDataValidationOptionsCommand: ICommand<IUpdateDataValidationOptionsCommandParams> = {
+ type: CommandType.COMMAND,
+ id: 'data-validation.command.updateDataValidationSetting',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const commandService = accessor.get(ICommandService);
+ const redoUndoService = accessor.get(IUndoRedoService);
+ const dataValidationModel = accessor.get(DataValidationModel);
+
+ const { unitId, subUnitId, ruleId, options } = params;
+
+ const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
+ if (!rule) {
+ return false;
+ }
+
+ const mutationParams: IUpdateDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId,
+ payload: {
+ type: UpdateRuleType.OPTIONS,
+ payload: options,
+ },
+ };
+
+ const redoMutations: IMutationInfo[] = [{
+ id: UpdateDataValidationMutation.id,
+ params: mutationParams,
+ }];
+ const undoMutationParams: IUpdateDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId,
+ payload: {
+ type: UpdateRuleType.OPTIONS,
+ payload: getRuleOptions(rule),
+ },
+ };
+ const undoMutations: IMutationInfo[] = [{
+ id: UpdateDataValidationMutation.id,
+ params: undoMutationParams,
+ }];
+
+ redoUndoService.pushUndoRedo({
+ unitID: unitId,
+ redoMutations,
+ undoMutations,
+ });
+
+ commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
+ return true;
+ },
+};
+
+export interface IUpdateDataValidationSettingCommandParams extends ISheetCommandSharedParams {
+ ruleId: string;
+ setting: IDataValidationRuleBase;
+}
+
+export const UpdateDataValidationSettingCommand: ICommand<IUpdateDataValidationSettingCommandParams> = {
+ type: CommandType.COMMAND,
+ id: 'data-validation.command.updateDataValidationOptions',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const commandService = accessor.get(ICommandService);
+ const redoUndoService = accessor.get(IUndoRedoService);
+ const dataValidationModel = accessor.get(DataValidationModel);
+ const dataValidatorRegistryService = accessor.get(DataValidatorRegistryService);
+
+ const { unitId, subUnitId, ruleId, setting } = params;
+ const validator = dataValidatorRegistryService.getValidatorItem(setting.type);
+
+ if (!validator) {
+ return false;
+ }
+
+ if (!validator.validatorFormula(setting).success) {
+ return false;
+ }
+
+ const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
+ if (!rule) {
+ return false;
+ }
+
+ const mutationParams: IUpdateDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId,
+ payload: {
+ type: UpdateRuleType.SETTING,
+ payload: setting,
+ },
+ };
+
+ const redoMutations: IMutationInfo[] = [{
+ id: UpdateDataValidationMutation.id,
+ params: mutationParams,
+ }];
+ const undoMutationParams: IUpdateDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId,
+ payload: {
+ type: UpdateRuleType.SETTING,
+ payload: getRuleSetting(rule),
+ },
+ };
+ const undoMutations: IMutationInfo[] = [{
+ id: UpdateDataValidationMutation.id,
+ params: undoMutationParams,
+ }];
+
+ redoUndoService.pushUndoRedo({
+ unitID: unitId,
+ redoMutations,
+ undoMutations,
+ });
+
+ commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
+ return true;
+ },
+};
+
+export interface IRemoveAllDataValidationCommandParams extends ISheetCommandSharedParams {
+}
+
+export const RemoveAllDataValidationCommand: ICommand<IRemoveAllDataValidationCommandParams> = {
+ type: CommandType.COMMAND,
+ id: 'data-validation.command.removeAll',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const { unitId, subUnitId } = params;
+ const commandService = accessor.get(ICommandService);
+ const dataValidationModel = accessor.get(DataValidationModel);
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const currentRules = [...dataValidationModel.getRules(unitId, subUnitId)];
+
+ const redoParams: IRemoveDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId: currentRules.map((rule) => rule.uid),
+ };
+ const redoMutations: IMutationInfo[] = [{
+ id: RemoveDataValidationMutation.id,
+ params: redoParams,
+ }];
+
+ const undoMutations: IMutationInfo[] = [{
+ id: AddDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ rule: currentRules,
+ },
+ }];
+
+ undoRedoService.pushUndoRedo({
+ redoMutations,
+ undoMutations,
+ unitID: unitId,
+ });
+
+ commandService.executeCommand(RemoveDataValidationMutation.id, redoParams);
+ return true;
+ },
+};
diff --git a/packages/data-validation/src/commands/mutations/data-validation.mutation.ts b/packages/data-validation/src/commands/mutations/data-validation.mutation.ts
new file mode 100644
index 0000000000..f162f2278b
--- /dev/null
+++ b/packages/data-validation/src/commands/mutations/data-validation.mutation.ts
@@ -0,0 +1,93 @@
+/**
+ * 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 { CommandType } from '@univerjs/core';
+import type { ICommand, IDataValidationRule } from '@univerjs/core';
+import type { ISheetCommandSharedParams } from '@univerjs/sheets';
+import type { IUpdateRulePayload } from '../../types/interfaces/i-update-rule-payload';
+import { DataValidationModel } from '../../models/data-validation-model';
+
+export interface IAddDataValidationMutationParams extends ISheetCommandSharedParams {
+ rule: IDataValidationRule | IDataValidationRule[];
+ index?: number;
+}
+
+export const AddDataValidationMutation: ICommand<IAddDataValidationMutationParams> = {
+ type: CommandType.MUTATION,
+ id: 'data-validation.mutation.addRule',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const { unitId, subUnitId, rule, index } = params;
+ const dataValidationModel = accessor.get(DataValidationModel);
+ if (Array.isArray(rule)) {
+ rule.forEach((ruleItem) => {
+ dataValidationModel.addRule(unitId, subUnitId, ruleItem, index);
+ });
+ } else {
+ dataValidationModel.addRule(unitId, subUnitId, rule!, index);
+ }
+
+ return true;
+ },
+};
+
+export interface IRemoveDataValidationMutationParams extends ISheetCommandSharedParams {
+ ruleId: string | string[];
+}
+
+export const RemoveDataValidationMutation: ICommand<IRemoveDataValidationMutationParams> = {
+ type: CommandType.MUTATION,
+ id: 'data-validation.mutation.removeRule',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+
+ const { unitId, subUnitId, ruleId } = params;
+ const dataValidationModel = accessor.get(DataValidationModel);
+ if (Array.isArray(ruleId)) {
+ ruleId.forEach((item) => {
+ dataValidationModel.removeRule(unitId, subUnitId, item);
+ });
+ } else {
+ dataValidationModel.removeRule(unitId, subUnitId, ruleId);
+ }
+
+ return true;
+ },
+};
+
+export interface IUpdateDataValidationMutationParams extends ISheetCommandSharedParams {
+ payload: IUpdateRulePayload;
+ ruleId: string;
+}
+
+export const UpdateDataValidationMutation: ICommand<IUpdateDataValidationMutationParams> = {
+ type: CommandType.MUTATION,
+ id: 'data-validation.mutation.updateRule',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+
+ const { unitId, subUnitId, ruleId, payload } = params;
+ const dataValidationModel = accessor.get(DataValidationModel);
+ dataValidationModel.updateRule(unitId, subUnitId, ruleId, payload);
+ return true;
+ },
+};
diff --git a/packages/data-validation/src/common/util.ts b/packages/data-validation/src/common/util.ts
new file mode 100644
index 0000000000..7454cfdd46
--- /dev/null
+++ b/packages/data-validation/src/common/util.ts
@@ -0,0 +1,59 @@
+/**
+ * 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 { DataValidationOperator, DataValidationType, type IDataValidationRule, type IDataValidationRuleBase, type IDataValidationRuleOptions, Tools } from '@univerjs/core';
+import { SelectionManagerService } from '@univerjs/sheets';
+import type { IAccessor } from '@wendellhu/redi';
+
+export function getRuleSetting(rule: IDataValidationRule): IDataValidationRuleBase {
+ return {
+ type: rule.type,
+ operator: rule.operator,
+ formula1: rule.formula1,
+ formula2: rule.formula2,
+ allowBlank: rule.allowBlank,
+ };
+}
+
+export function getRuleOptions(rule: IDataValidationRule): IDataValidationRuleOptions {
+ return {
+ error: rule.error,
+ errorStyle: rule.errorStyle,
+ errorTitle: rule.errorTitle,
+ imeMode: rule.imeMode,
+ prompt: rule.prompt,
+ promptTitle: rule.promptTitle,
+ showDropDown: rule.showDropDown,
+ showErrorMessage: rule.showErrorMessage,
+ showInputMessage: rule.showInputMessage,
+ renderMode: rule.renderMode,
+ };
+}
+
+export function createDefaultNewRule(accessor: IAccessor) {
+ const selectionManagerService = accessor.get(SelectionManagerService);
+ const currentRanges = selectionManagerService.getSelectionRanges();
+ const uid = Tools.generateRandomId(6);
+ const rule = {
+ uid,
+ type: DataValidationType.DECIMAL,
+ operator: DataValidationOperator.EQUAL,
+ formula1: '100',
+ ranges: currentRanges ?? [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }],
+ };
+
+ return rule;
+}
diff --git a/packages/data-validation/src/index.ts b/packages/data-validation/src/index.ts
new file mode 100644
index 0000000000..51764aaa7d
--- /dev/null
+++ b/packages/data-validation/src/index.ts
@@ -0,0 +1,63 @@
+/**
+ * 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.
+ */
+
+export { UniverDataValidationPlugin } from './plugin';
+export { DataValidatorRegistryService, DataValidatorRegistryScope } from './services/data-validator-registry.service';
+export { DataValidationModel } from './models/data-validation-model';
+
+export {
+ AddDataValidationCommand,
+ RemoveDataValidationCommand,
+ RemoveAllDataValidationCommand,
+ UpdateDataValidationOptionsCommand,
+ UpdateDataValidationSettingCommand,
+} from './commands/commands/data-validation.command';
+
+export type {
+ IRemoveDataValidationCommandParams,
+ IAddDataValidationCommandParams,
+ IUpdateDataValidationOptionsCommandParams,
+ IUpdateDataValidationSettingCommandParams,
+ IRemoveAllDataValidationCommandParams,
+} from './commands/commands/data-validation.command';
+
+export {
+ AddDataValidationMutation,
+ RemoveDataValidationMutation,
+ UpdateDataValidationMutation,
+
+} from './commands/mutations/data-validation.mutation';
+
+export type {
+ IAddDataValidationMutationParams,
+ IRemoveDataValidationMutationParams,
+ IUpdateDataValidationMutationParams,
+} from './commands/mutations/data-validation.mutation';
+
+export {
+ createDefaultNewRule,
+ getRuleOptions,
+ getRuleSetting,
+} from './common/util';
+
+export { UpdateRuleType } from './types/enum/update-rule-type';
+export type { IDataValidatorOperatorConfig } from './types/interfaces/i-data-validator-operator-config';
+export type { IFormulaInputProps, IFormulaValue, FormulaInputType } from './types/interfaces/i-formula-input';
+export type { IUpdateRuleOptionsPayload, IUpdateRulePayload, IUpdateRuleRangePayload, IUpdateRuleSettingPayload } from './types/interfaces/i-update-rule-payload';
+export type { IDataValidationDropdownProps } from './types/interfaces/i-data-validation-drop-down';
+export { BaseDataValidator } from './validators/base-data-validator';
+export type { IFormulaResult, IValidatorCellInfo } from './validators/base-data-validator';
+export type { IBaseDataValidationWidget } from './validators/base-widget';
diff --git a/packages/data-validation/src/models/data-validation-manager.ts b/packages/data-validation/src/models/data-validation-manager.ts
new file mode 100644
index 0000000000..aa06eb5c39
--- /dev/null
+++ b/packages/data-validation/src/models/data-validation-manager.ts
@@ -0,0 +1,132 @@
+/**
+ * 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 type { CellValue, IDataValidationRule, Nullable } from '@univerjs/core';
+import { DataValidationStatus, Disposable } from '@univerjs/core';
+import { Subject } from 'rxjs';
+import type { IUpdateRulePayload } from '../types/interfaces/i-update-rule-payload';
+import { UpdateRuleType } from '../types/enum/update-rule-type';
+
+export class DataValidationManager<T extends IDataValidationRule> extends Disposable {
+ private _dataValidations: T[];
+ private _dataValidationMap = new Map<string, T>();
+ private _dataValidations$ = new Subject<T[]>();
+
+ readonly unitId: string;
+ readonly subUnitId: string;
+ readonly dataValidations$ = this._dataValidations$.asObservable();
+
+ constructor(unitId: string, subUnitId: string, dataValidations: T[] | undefined) {
+ super();
+ this.unitId = unitId;
+ this.subUnitId = subUnitId;
+ if (!dataValidations) {
+ return;
+ }
+
+ this._insertRules(dataValidations);
+ this._notice();
+
+ this.disposeWithMe({
+ dispose: () => {
+ this._dataValidations$.complete();
+ },
+ });
+ }
+
+ private _notice() {
+ this._dataValidations$.next(this._dataValidations);
+ }
+
+ private _insertRules(dataValidations: T[]) {
+ this._dataValidations = dataValidations;
+ dataValidations.forEach((validation) => {
+ this._dataValidationMap.set(validation.uid, validation);
+ });
+ }
+
+ getRuleById(id: string) {
+ return this._dataValidationMap.get(id);
+ }
+
+ getRuleIndex(id: string) {
+ return this._dataValidations.findIndex((rule) => rule.uid === id);
+ }
+
+ addRule(rule: T, index?: number) {
+ if (typeof index === 'number' && index < this._dataValidations.length) {
+ this._dataValidations.splice(index, 0, rule);
+ } else {
+ this._dataValidations.push(rule);
+ }
+
+ this._dataValidationMap.set(rule.uid, rule);
+ this._notice();
+ }
+
+ removeRule(ruleId: string) {
+ const index = this._dataValidations.findIndex((item) => item.uid === ruleId);
+ this._dataValidations.splice(index, 1);
+ this._dataValidationMap.delete(ruleId);
+ this._notice();
+ }
+
+ updateRule(ruleId: string, payload: IUpdateRulePayload) {
+ const oldRule = this._dataValidationMap.get(ruleId);
+ const index = this._dataValidations.findIndex((rule) => ruleId === rule.uid);
+
+ if (!oldRule) {
+ throw new Error(`Data validation rule is not found, ruleId: ${ruleId}.`);
+ }
+
+ const rule = { ...oldRule };
+
+ switch (payload.type) {
+ case UpdateRuleType.RANGE: {
+ rule.ranges = payload.payload;
+ break;
+ }
+ case UpdateRuleType.SETTING: {
+ Object.assign(rule, payload.payload);
+ break;
+ }
+
+ case UpdateRuleType.OPTIONS: {
+ Object.assign(rule, payload.payload);
+ break;
+ }
+ default:
+ break;
+ }
+
+ this._dataValidations[index] = rule;
+ this._dataValidationMap.set(ruleId, rule);
+ this._notice();
+ return rule;
+ }
+
+ getDataValidations() {
+ return this._dataValidations;
+ }
+
+ toJSON() {
+ return this._dataValidations;
+ }
+
+ validator(_content: Nullable<CellValue>, _rule: IDataValidationRule, _pos: any, _onCompele: (status: DataValidationStatus) => void) {
+ return DataValidationStatus.VALID;
+ }
+}
diff --git a/packages/data-validation/src/models/data-validation-model.ts b/packages/data-validation/src/models/data-validation-model.ts
new file mode 100644
index 0000000000..f4e31ac590
--- /dev/null
+++ b/packages/data-validation/src/models/data-validation-model.ts
@@ -0,0 +1,169 @@
+/**
+ * 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 { type CellValue, type DataValidationStatus, Disposable, type IDataValidationRule, ILogService, type Nullable } from '@univerjs/core';
+import { debounceTime, Subject } from 'rxjs';
+import type { IUpdateRulePayload } from '../types/interfaces/i-update-rule-payload';
+import type { DataValidationManager } from './data-validation-manager';
+
+type ManagerCreator<T extends IDataValidationRule> = (unitId: string, subUnitId: string) => DataValidationManager<T>;
+type RuleChangeType = 'update' | 'add' | 'remove';
+
+export interface IRuleChange<T extends IDataValidationRule> {
+ rule?: T;
+ type: RuleChangeType;
+ unitId: string;
+ subUnitId: string;
+}
+
+export interface IValidStatusChange {
+ unitId: string;
+ subUnitId: string;
+ ruleId: string;
+ status: DataValidationStatus;
+}
+
+export class DataValidationModel<T extends IDataValidationRule = IDataValidationRule> extends Disposable {
+ private readonly _model = new Map<string, Map<string, DataValidationManager<T>>>();
+ private _managerCreator: ManagerCreator<T>;
+ private readonly _ruleChange$ = new Subject<IRuleChange<T>>();
+ private readonly _validStatusChange$ = new Subject<IValidStatusChange>();
+
+ ruleChange$ = this._ruleChange$.asObservable();
+ ruleChangeDebounce$ = this.ruleChange$.pipe(debounceTime(20));
+ validStatusChange$ = this._validStatusChange$.asObservable().pipe(debounceTime(20));
+
+ constructor(
+ @ILogService private readonly _logService: ILogService
+ ) {
+ super();
+
+ this.disposeWithMe({
+ dispose: () => {
+ this._ruleChange$.complete();
+ this._validStatusChange$.complete();
+ },
+ });
+ }
+
+ setManagerCreator(creator: (unitId: string, subUnitId: string) => DataValidationManager<T>) {
+ this._managerCreator = creator;
+ }
+
+ ensureManager(unitId: string, subUnitId: string) {
+ if (!this._model.has(unitId)) {
+ this._model.set(unitId, new Map());
+ }
+ const unitMap = this._model.get(unitId)!;
+
+ if (unitMap.has(subUnitId)) {
+ return unitMap.get(subUnitId)!;
+ }
+
+ const manager = this._managerCreator(unitId, subUnitId);
+ unitMap.set(subUnitId, manager);
+ return manager;
+ }
+
+ addRule(unitId: string, subUnitId: string, rule: T, index?: number) {
+ try {
+ const manager = this.ensureManager(unitId, subUnitId);
+ manager.addRule(rule, index);
+ this._ruleChange$.next({
+ rule: rule as any,
+ type: 'add',
+ unitId,
+ subUnitId,
+ });
+ } catch (error) {
+ this._logService.error(error);
+ }
+ }
+
+ updateRule(unitId: string, subUnitId: string, ruleId: string, payload: IUpdateRulePayload) {
+ try {
+ const manager = this.ensureManager(unitId, subUnitId);
+ const rule = manager.updateRule(ruleId, payload);
+
+ this._ruleChange$.next({
+ rule,
+ type: 'update',
+ unitId,
+ subUnitId,
+ });
+ } catch (error) {
+ this._logService.error(error);
+ }
+ }
+
+ removeRule(unitId: string, subUnitId: string, ruleId: string) {
+ try {
+ const manager = this.ensureManager(unitId, subUnitId);
+ const oldRule = manager.getRuleById(ruleId);
+ manager.removeRule(ruleId);
+ this._ruleChange$.next({
+ rule: oldRule,
+ type: 'remove',
+ unitId,
+ subUnitId,
+ });
+ } catch (error) {
+ this._logService.error(error);
+ }
+ }
+
+ getRuleById(unitId: string, subUnitId: string, ruleId: string) {
+ const manager = this.ensureManager(unitId, subUnitId);
+ return manager.getRuleById(ruleId);
+ }
+
+ getRuleIndex(unitId: string, subUnitId: string, ruleId: string) {
+ const manager = this.ensureManager(unitId, subUnitId);
+ return manager.getRuleIndex(ruleId);
+ }
+
+ getRules(unitId: string, subUnitId: string) {
+ const manager = this.ensureManager(unitId, subUnitId);
+ return manager.getDataValidations();
+ }
+
+ validator(content: Nullable<CellValue>, rule: T, pos: any) {
+ const { unitId, subUnitId } = pos;
+ const manager = this.ensureManager(unitId, subUnitId);
+ return manager.validator(content, rule, pos, (status: DataValidationStatus) => {
+ this._validStatusChange$.next({
+ unitId,
+ subUnitId,
+ ruleId: rule.uid,
+ status,
+ });
+ });
+ }
+
+ getUnitRules(unitId: string) {
+ const unitMap = this._model.get(unitId);
+ if (!unitMap) {
+ return [];
+ }
+ const res = [] as [string, IDataValidationRule[]][];
+
+ unitMap.forEach((manager) => {
+ res.push([manager.subUnitId, manager.getDataValidations()]);
+ });
+
+ return res;
+ }
+}
diff --git a/packages/data-validation/src/plugin.ts b/packages/data-validation/src/plugin.ts
new file mode 100644
index 0000000000..8fcf9d2ee5
--- /dev/null
+++ b/packages/data-validation/src/plugin.ts
@@ -0,0 +1,65 @@
+/**
+ * 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 { ICommandService, Plugin } from '@univerjs/core';
+import type { Dependency } from '@wendellhu/redi';
+import { Inject, Injector } from '@wendellhu/redi';
+import { DataValidatorRegistryService } from './services/data-validator-registry.service';
+import { DataValidationModel } from './models/data-validation-model';
+import { AddDataValidationCommand, RemoveAllDataValidationCommand, RemoveDataValidationCommand, UpdateDataValidationOptionsCommand, UpdateDataValidationSettingCommand } from './commands/commands/data-validation.command';
+import { AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation } from './commands/mutations/data-validation.mutation';
+
+const PLUGIN_NAME = 'data-validation';
+
+export class UniverDataValidationPlugin extends Plugin {
+ constructor(
+ @Inject(Injector) protected _injector: Injector,
+ @ICommandService private _commandService: ICommandService
+ ) {
+ super(PLUGIN_NAME);
+ }
+
+ override onStarting(injector: Injector): void {
+ ([
+ // model
+ [DataValidationModel],
+
+ // service
+ [DataValidatorRegistryService],
+
+ ] as Dependency[]).forEach(
+ (d) => {
+ injector.add(d);
+ }
+ );
+
+ [
+ // command
+ AddDataValidationCommand,
+ RemoveAllDataValidationCommand,
+ UpdateDataValidationOptionsCommand,
+ UpdateDataValidationSettingCommand,
+ RemoveDataValidationCommand,
+
+ // mutation
+ AddDataValidationMutation,
+ UpdateDataValidationMutation,
+ RemoveDataValidationMutation,
+ ].forEach((command) => {
+ this._commandService.registerCommand(command);
+ });
+ }
+}
diff --git a/packages/data-validation/src/services/data-validator-registry.service.ts b/packages/data-validation/src/services/data-validator-registry.service.ts
new file mode 100644
index 0000000000..376eb8fd3f
--- /dev/null
+++ b/packages/data-validation/src/services/data-validator-registry.service.ts
@@ -0,0 +1,95 @@
+/**
+ * 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 { toDisposable } from '@univerjs/core';
+import { BehaviorSubject } from 'rxjs';
+import type { BaseDataValidator } from '../validators/base-data-validator';
+
+export enum DataValidatorRegistryScope {
+ SHEET = 'sheet',
+}
+
+/**
+ * Register data validator
+ */
+export class DataValidatorRegistryService {
+ private _validatorByScopes = new Map<string, Array<BaseDataValidator>>();
+
+ private _validatorMap = new Map<string, BaseDataValidator>();
+
+ private _validatorsChange$ = new BehaviorSubject<void>(undefined);
+ validatorsChange$ = this._validatorsChange$.asObservable();
+
+ private _addValidatorToScope(validator: BaseDataValidator, scope: string) {
+ if (!this._validatorByScopes.has(scope)) {
+ this._validatorByScopes.set(scope, []);
+ }
+
+ const validators = this._validatorByScopes.get(scope)!;
+ if (validators.findIndex((m) => m.id === validator.id) > -1) {
+ throw new Error(`Validator item with the same id ${validator.id} has already been added!`);
+ }
+ validators.push(validator);
+ }
+
+ private _removeValidatorFromScope(validator: BaseDataValidator, scope: string) {
+ const validators = this._validatorByScopes.get(scope);
+ if (!validators) {
+ return;
+ }
+
+ const index = validators.findIndex((v) => v.id === validator.id);
+ if (index > -1) {
+ validators.splice(index, 1);
+ }
+ }
+
+ register(validator: BaseDataValidator<any>) {
+ this._validatorMap.set(validator.id, validator);
+
+ if (Array.isArray(validator.scopes)) {
+ validator.scopes.forEach((scope) => {
+ this._addValidatorToScope(validator, scope);
+ });
+ } else {
+ this._addValidatorToScope(validator, validator.scopes);
+ }
+
+ this._validatorsChange$.next();
+
+ return toDisposable(() => {
+ this._validatorMap.delete(validator.id);
+
+ if (Array.isArray(validator.scopes)) {
+ validator.scopes.forEach((scope) => {
+ this._removeValidatorFromScope(validator, scope);
+ });
+ } else {
+ this._removeValidatorFromScope(validator, validator.scopes);
+ }
+
+ this._validatorsChange$.next();
+ });
+ }
+
+ getValidatorItem(id: string) {
+ return this._validatorMap.get(id);
+ }
+
+ getValidatorsByScope(scope: string) {
+ return this._validatorByScopes.get(scope);
+ }
+}
diff --git a/packages/data-validation/src/types/const/operator-text-map.ts b/packages/data-validation/src/types/const/operator-text-map.ts
new file mode 100644
index 0000000000..82622a5c48
--- /dev/null
+++ b/packages/data-validation/src/types/const/operator-text-map.ts
@@ -0,0 +1,50 @@
+/**
+ * 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 { DataValidationOperator } from '@univerjs/core';
+
+export const OperatorTextMap: Record<DataValidationOperator, string> = {
+ [DataValidationOperator.BETWEEN]: 'dataValidation.operators.between',
+ [DataValidationOperator.EQUAL]: 'dataValidation.operators.equal',
+ [DataValidationOperator.GREATER_THAN]: 'dataValidation.operators.greaterThan',
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: 'dataValidation.operators.greaterThanOrEqual',
+ [DataValidationOperator.LESS_THAN]: 'dataValidation.operators.lessThan',
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: 'dataValidation.operators.lessThanOrEqual',
+ [DataValidationOperator.NOT_BETWEEN]: 'dataValidation.operators.notBetween',
+ [DataValidationOperator.NOT_EQUAL]: 'dataValidation.operators.notEqual',
+};
+
+export const OperatorTitleMap: Record<DataValidationOperator, string> = {
+ [DataValidationOperator.BETWEEN]: 'dataValidation.ruleName.between',
+ [DataValidationOperator.EQUAL]: 'dataValidation.ruleName.equal',
+ [DataValidationOperator.GREATER_THAN]: 'dataValidation.ruleName.greaterThan',
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: 'dataValidation.ruleName.greaterThanOrEqual',
+ [DataValidationOperator.LESS_THAN]: 'dataValidation.ruleName.lessThan',
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: 'dataValidation.ruleName.lessThanOrEqual',
+ [DataValidationOperator.NOT_BETWEEN]: 'dataValidation.ruleName.notBetween',
+ [DataValidationOperator.NOT_EQUAL]: 'dataValidation.ruleName.notEqual',
+};
+
+export const OperatorErrorTitleMap: Record<DataValidationOperator, string> = {
+ [DataValidationOperator.BETWEEN]: 'dataValidation.errorMsg.between',
+ [DataValidationOperator.EQUAL]: 'dataValidation.errorMsg.equal',
+ [DataValidationOperator.GREATER_THAN]: 'dataValidation.errorMsg.greaterThan',
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: 'dataValidation.errorMsg.greaterThanOrEqual',
+ [DataValidationOperator.LESS_THAN]: 'dataValidation.errorMsg.lessThan',
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: 'dataValidation.errorMsg.lessThanOrEqual',
+ [DataValidationOperator.NOT_BETWEEN]: 'dataValidation.errorMsg.notBetween',
+ [DataValidationOperator.NOT_EQUAL]: 'dataValidation.errorMsg.notEqual',
+};
diff --git a/packages/data-validation/src/types/const/two-formula-operators.ts b/packages/data-validation/src/types/const/two-formula-operators.ts
new file mode 100644
index 0000000000..5c263a039d
--- /dev/null
+++ b/packages/data-validation/src/types/const/two-formula-operators.ts
@@ -0,0 +1,22 @@
+/**
+ * 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 { DataValidationOperator } from '@univerjs/core';
+
+export const TWO_FORMULA_OPERATOR_COUNT: DataValidationOperator[] = [
+ DataValidationOperator.BETWEEN,
+ DataValidationOperator.NOT_BETWEEN,
+];
diff --git a/packages/data-validation/src/types/enum/update-rule-type.ts b/packages/data-validation/src/types/enum/update-rule-type.ts
new file mode 100644
index 0000000000..a92a537861
--- /dev/null
+++ b/packages/data-validation/src/types/enum/update-rule-type.ts
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+export enum UpdateRuleType {
+ SETTING,
+ RANGE,
+ OPTIONS,
+}
diff --git a/packages/data-validation/src/types/interfaces/i-data-validation-drop-down.ts b/packages/data-validation/src/types/interfaces/i-data-validation-drop-down.ts
new file mode 100644
index 0000000000..7098e59041
--- /dev/null
+++ b/packages/data-validation/src/types/interfaces/i-data-validation-drop-down.ts
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+
+export interface IDataValidationDropdownProps {
+ top: number;
+ left: number;
+ width: number;
+ height: number;
+ unitId: string;
+ subUnitId: string;
+ row: number;
+ col: number;
+}
diff --git a/packages/data-validation/src/types/interfaces/i-data-validator-operator-config.ts b/packages/data-validation/src/types/interfaces/i-data-validator-operator-config.ts
new file mode 100644
index 0000000000..81ee23ff83
--- /dev/null
+++ b/packages/data-validation/src/types/interfaces/i-data-validator-operator-config.ts
@@ -0,0 +1,25 @@
+/**
+ * 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 type { DataValidationOperator } from '@univerjs/core';
+
+export interface IDataValidatorOperatorConfig {
+ operator: DataValidationOperator;
+ text: string;
+ placeholder1?: string;
+ placeholder2?: string;
+ formulaCount: 1 | 2;
+}
diff --git a/packages/data-validation/src/types/interfaces/i-formula-input.ts b/packages/data-validation/src/types/interfaces/i-formula-input.ts
new file mode 100644
index 0000000000..06bc0a71a7
--- /dev/null
+++ b/packages/data-validation/src/types/interfaces/i-formula-input.ts
@@ -0,0 +1,34 @@
+/**
+ * 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 type { IFormulaValidResult } from '../../validators/base-data-validator';
+
+export interface IFormulaValue {
+ formula1?: string;
+ formula2?: string;
+}
+
+export interface IFormulaInputProps {
+ isTwoFormula?: boolean;
+ value?: IFormulaValue;
+ onChange?: (value?: IFormulaValue) => void;
+ unitId: string;
+ subUnitId: string;
+ showError?: boolean;
+ validResult?: IFormulaValidResult;
+}
+
+export type FormulaInputType = React.ComponentType<IFormulaInputProps>;
diff --git a/packages/data-validation/src/types/interfaces/i-update-rule-payload.ts b/packages/data-validation/src/types/interfaces/i-update-rule-payload.ts
new file mode 100644
index 0000000000..4a35826787
--- /dev/null
+++ b/packages/data-validation/src/types/interfaces/i-update-rule-payload.ts
@@ -0,0 +1,38 @@
+/**
+ * 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 type { IDataValidationRuleBase, IDataValidationRuleOptions } from '@univerjs/core';
+import type { UpdateRuleType } from '../enum/update-rule-type';
+
+export interface IUpdateRuleRangePayload {
+ type: UpdateRuleType.RANGE;
+ payload: any[];
+}
+
+export interface IUpdateRuleSettingPayload {
+ type: UpdateRuleType.SETTING;
+ payload: IDataValidationRuleBase;
+}
+
+export interface IUpdateRuleOptionsPayload {
+ type: UpdateRuleType.OPTIONS;
+ payload: Partial<IDataValidationRuleOptions>;
+}
+
+export type IUpdateRulePayload =
+ IUpdateRuleRangePayload
+ | IUpdateRuleSettingPayload
+ | IUpdateRuleOptionsPayload;
diff --git a/packages/data-validation/src/validators/base-data-validator.ts b/packages/data-validation/src/validators/base-data-validator.ts
new file mode 100644
index 0000000000..b62078d389
--- /dev/null
+++ b/packages/data-validation/src/validators/base-data-validator.ts
@@ -0,0 +1,209 @@
+/**
+ * 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 type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
+import { DataValidationOperator, LocaleService, Tools } from '@univerjs/core';
+import { Inject, Injector } from '@wendellhu/redi';
+import { OperatorErrorTitleMap, OperatorTitleMap } from '../types/const/operator-text-map';
+import type { IBaseDataValidationWidget } from './base-widget';
+
+const FORMULA1 = '{FORMULA1}';
+const FORMULA2 = '{FORMULA2}';
+
+const operatorNameMap: Record<DataValidationOperator, string> = {
+ [DataValidationOperator.BETWEEN]: 'dataValidation.operators.between',
+ [DataValidationOperator.EQUAL]: 'dataValidation.operators.equal',
+ [DataValidationOperator.GREATER_THAN]: 'dataValidation.operators.greaterThan',
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: 'dataValidation.operators.greaterThanOrEqual',
+ [DataValidationOperator.LESS_THAN]: 'dataValidation.operators.lessThan',
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: 'dataValidation.operators.lessThanOrEqual',
+ [DataValidationOperator.NOT_BETWEEN]: 'dataValidation.operators.notBetween',
+ [DataValidationOperator.NOT_EQUAL]: 'dataValidation.operators.notEqual',
+};
+
+export interface IValidatorCellInfo<DataType = Nullable<CellValue>> {
+ value: DataType;
+ row: number;
+ column: number;
+ unitId: string;
+ subUnitId: string;
+}
+
+export interface IFormulaResult<T = any> {
+ formula1: T;
+ formula2: T;
+}
+
+export interface IFormulaValidResult {
+ success: boolean;
+ formula1?: string;
+ formula2?: string;
+}
+
+export abstract class BaseDataValidator<DataType = CellValue> {
+ abstract id: string;
+
+ abstract title: string;
+
+ abstract operators: DataValidationOperator[];
+
+ abstract scopes: string[] | string;
+
+ abstract formulaInput: string;
+
+ canvasRender: Nullable<IBaseDataValidationWidget> = null;
+
+ dropdown: string | undefined = undefined;
+
+ optionsInput: string | undefined = undefined;
+
+ constructor(
+ @Inject(LocaleService) readonly localeService: LocaleService,
+ @Inject(Injector) readonly injector: Injector
+ ) { }
+
+ get operatorNames() {
+ return this.operators.map((operator) => this.localeService.t(operatorNameMap[operator]));
+ }
+
+ get titleStr() {
+ return this.localeService.t(this.title);
+ }
+
+ skipDefaultFontRender(rule: IDataValidationRule, cellValue: Nullable<CellValue>, pos: any) {
+ return false;
+ };
+
+ generateRuleName(rule: IDataValidationRuleBase): string {
+ if (!rule.operator) {
+ return this.titleStr;
+ }
+
+ const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? '').replace(FORMULA2, rule.formula2 ?? '');
+ return `${this.titleStr} ${ruleName}`;
+ }
+
+ generateRuleErrorMessage(rule: IDataValidationRuleBase) {
+ if (!rule.operator) {
+ return this.titleStr;
+ }
+
+ const errorMsg = this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? '').replace(FORMULA2, rule.formula2 ?? '');
+ return `${errorMsg}`;
+ }
+
+ getRuleFinalError(rule: IDataValidationRule) {
+ if (rule.showInputMessage && rule.error) {
+ return rule.error;
+ }
+
+ return this.generateRuleErrorMessage(rule);
+ }
+
+ isEmptyCellValue(cellValue: Nullable<CellValue>): cellValue is null | undefined | void {
+ if (cellValue === '' || cellValue === undefined || cellValue === null) {
+ return true;
+ }
+
+ return false;
+ }
+
+ abstract parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult>;
+
+ abstract validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult;
+
+ async isValidType(cellInfo: IValidatorCellInfo, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ transform(cellInfo: IValidatorCellInfo, formula: IFormulaResult, rule: IDataValidationRule): IValidatorCellInfo<DataType> {
+ return cellInfo as IValidatorCellInfo<DataType>;
+ };
+
+ async validatorIsEqual(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validatorIsNotEqual(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validatorIsBetween(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validatorIsNotBetween(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validatorIsGreaterThan(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validatorIsGreaterThanOrEqual(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validatorIsLessThan(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<DataType>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ return true;
+ };
+
+ async validator(cellInfo: IValidatorCellInfo, rule: IDataValidationRule): Promise<boolean> {
+ const { value: cellValue, unitId, subUnitId } = cellInfo;
+ const isEmpty = this.isEmptyCellValue(cellValue);
+ const { allowBlank = true, operator } = rule;
+ if (isEmpty) {
+ return allowBlank;
+ }
+
+ const formulaInfo = await this.parseFormula(rule, unitId, subUnitId);
+
+ if (!(await this.isValidType(cellInfo, formulaInfo, rule))) {
+ return false;
+ }
+
+ if (!Tools.isDefine(operator)) {
+ return true;
+ }
+
+ const transformedCell = this.transform(cellInfo, formulaInfo, rule);
+
+ switch (operator) {
+ case DataValidationOperator.BETWEEN:
+ return this.validatorIsBetween(transformedCell, formulaInfo, rule);
+ case DataValidationOperator.EQUAL:
+ return this.validatorIsEqual(transformedCell, formulaInfo, rule);
+ case DataValidationOperator.GREATER_THAN:
+ return this.validatorIsGreaterThan(transformedCell, formulaInfo, rule);
+ case DataValidationOperator.GREATER_THAN_OR_EQUAL:
+ return this.validatorIsGreaterThanOrEqual(transformedCell, formulaInfo, rule);
+ case DataValidationOperator.LESS_THAN:
+ return this.validatorIsLessThan(transformedCell, formulaInfo, rule);
+ case DataValidationOperator.LESS_THAN_OR_EQUAL:
+ return this.validatorIsLessThanOrEqual(transformedCell, formulaInfo, rule);
+ case DataValidationOperator.NOT_BETWEEN:
+ return this.validatorIsNotBetween(transformedCell, formulaInfo, rule);
+ case DataValidationOperator.NOT_EQUAL:
+ return this.validatorIsNotEqual(transformedCell, formulaInfo, rule);
+ default:
+ throw new Error('Unknown operator.');
+ }
+ }
+}
diff --git a/packages/data-validation/src/validators/base-widget.ts b/packages/data-validation/src/validators/base-widget.ts
new file mode 100644
index 0000000000..2505002a6e
--- /dev/null
+++ b/packages/data-validation/src/validators/base-widget.ts
@@ -0,0 +1,21 @@
+/**
+ * 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 type { ICellCustomRender, ICellRenderContext } from '@univerjs/core';
+
+export interface IBaseDataValidationWidget extends ICellCustomRender {
+ calcCellAutoHeight(info: ICellRenderContext): number | undefined;
+}
diff --git a/packages/data-validation/src/vite-env.d.ts b/packages/data-validation/src/vite-env.d.ts
new file mode 100644
index 0000000000..11f02fe2a0
--- /dev/null
+++ b/packages/data-validation/src/vite-env.d.ts
@@ -0,0 +1 @@
+/// <reference types="vite/client" />
diff --git a/packages/data-validation/tsconfig.json b/packages/data-validation/tsconfig.json
new file mode 100644
index 0000000000..d676ad2a20
--- /dev/null
+++ b/packages/data-validation/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "extends": "@univerjs/shared/tsconfigs/base",
+ "compilerOptions": {
+ "rootDir": "src",
+ "outDir": "lib/types"
+ },
+ "references": [{ "path": "./tsconfig.node.json" }],
+ "include": ["src"]
+}
diff --git a/packages/data-validation/tsconfig.node.json b/packages/data-validation/tsconfig.node.json
new file mode 100644
index 0000000000..e53dac8868
--- /dev/null
+++ b/packages/data-validation/tsconfig.node.json
@@ -0,0 +1,4 @@
+{
+ "extends": "@univerjs/shared/tsconfigs/node",
+ "include": ["vite.config.ts"]
+}
diff --git a/packages/data-validation/vite.config.ts b/packages/data-validation/vite.config.ts
new file mode 100644
index 0000000000..e38cd8530b
--- /dev/null
+++ b/packages/data-validation/vite.config.ts
@@ -0,0 +1,12 @@
+import createViteConfig from '@univerjs/shared/vite';
+import pkg from './package.json';
+
+export default ({ mode }) => createViteConfig({}, {
+ mode,
+ pkg,
+ features: {
+ react: true,
+ css: true,
+ dom: true,
+ },
+});
diff --git a/packages/design/src/components/date-picker/DatePicker.tsx b/packages/design/src/components/date-picker/DatePicker.tsx
index e2f336d287..98d9133367 100644
--- a/packages/design/src/components/date-picker/DatePicker.tsx
+++ b/packages/design/src/components/date-picker/DatePicker.tsx
@@ -15,6 +15,7 @@
*/
import React, { useContext } from 'react';
+import type { PickerProps } from 'rc-picker';
import RcPicker from 'rc-picker';
import generateConfig from 'rc-picker/lib/generate/dayjs';
import { CalendarSingle } from '@univerjs/icons';
@@ -22,7 +23,7 @@ import type { Dayjs } from 'dayjs';
import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';
-export interface IDatePickerProps {
+export interface IDatePickerProps extends Omit<PickerProps<Dayjs>, 'value' | 'onChange' | 'locale' | 'generateConfig' | 'prefixCls'> {
/**
* The value of the date picker.
*/
@@ -35,7 +36,7 @@ export interface IDatePickerProps {
}
export function DatePicker(props: IDatePickerProps) {
- const { value, onChange } = props;
+ const { value, onChange, ...ext } = props;
const { locale } = useContext(ConfigContext);
@@ -47,6 +48,7 @@ export function DatePicker(props: IDatePickerProps) {
return (
<RcPicker<Dayjs>
+ {...ext}
value={value}
prefixCls={styles.datePicker}
generateConfig={generateConfig}
diff --git a/packages/design/src/components/date-picker/Panel.tsx b/packages/design/src/components/date-picker/Panel.tsx
new file mode 100644
index 0000000000..c7695fe32b
--- /dev/null
+++ b/packages/design/src/components/date-picker/Panel.tsx
@@ -0,0 +1,37 @@
+/**
+ * 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 React, { useContext } from 'react';
+import type { Dayjs } from 'dayjs';
+import generateConfig from 'rc-picker/lib/generate/dayjs';
+import type { BasePickerPanelProps } from 'rc-picker';
+import { PickerPanel } from 'rc-picker';
+import { ConfigContext } from '../config-provider';
+import styles from './index.module.less';
+
+export type DatePanelProps = Omit<BasePickerPanelProps<Dayjs>, 'prefixCls' | 'locale' | 'generateConfig'>;
+
+export const DatePanel = (props: DatePanelProps) => {
+ const { locale } = useContext(ConfigContext);
+ return (
+ <PickerPanel
+ {...props}
+ generateConfig={generateConfig}
+ prefixCls={styles.datePicker}
+ locale={locale.design.Picker}
+ />
+ );
+};
diff --git a/packages/design/src/components/date-picker/index.ts b/packages/design/src/components/date-picker/index.ts
index 69bf782f2f..df93bae093 100644
--- a/packages/design/src/components/date-picker/index.ts
+++ b/packages/design/src/components/date-picker/index.ts
@@ -15,3 +15,5 @@
*/
export { DatePicker, type IDatePickerProps } from './DatePicker';
+export { DatePanel } from './Panel';
+export type { DatePanelProps } from './Panel';
diff --git a/packages/design/src/components/form-layout/FormLayout.stories.tsx b/packages/design/src/components/form-layout/FormLayout.stories.tsx
index 74f5db78b0..6360df4c94 100644
--- a/packages/design/src/components/form-layout/FormLayout.stories.tsx
+++ b/packages/design/src/components/form-layout/FormLayout.stories.tsx
@@ -38,7 +38,7 @@ function PagerDemo() {
<FormLayout label="行标题与列标题" desc="转到“查看”>“冻结”可选择要在所有页面重复的行/列">
<Input placeholder="请输入" />
</FormLayout>
- <FormLayout label="行标题与列标题" desc="转到“查看”>“冻结”可选择要在所有页面重复的行/列">
+ <FormLayout label="行标题与列标题" desc="转到“查看”>“冻结”可选择要在所有页面重复的行/列" error="123">
<Select value="" onChange={() => {}} />
</FormLayout>
</>
diff --git a/packages/design/src/components/form-layout/FormLayout.tsx b/packages/design/src/components/form-layout/FormLayout.tsx
index 2e269486c2..b8e70d081b 100644
--- a/packages/design/src/components/form-layout/FormLayout.tsx
+++ b/packages/design/src/components/form-layout/FormLayout.tsx
@@ -27,15 +27,26 @@ export interface IFormLayoutProps {
style?: React.CSSProperties;
className?: string;
+
+ error?: string;
}
export const FormLayout = (props: IFormLayoutProps) => {
- const { label, desc, children, style, className } = props;
+ const { label, desc, children, style, className, error } = props;
return (
<div className={clsx(styles.formLayout, className)} style={style}>
{label && <div className={styles.formLayoutLabel}>{label}</div>}
{desc && <div className={styles.formLayoutDesc}>{desc}</div>}
- <div className={styles.formLayoutContent}>{children}</div>
+ <div className={clsx(styles.formLayoutContent, error ? styles.formLayoutContentError : '')}>
+ {children}
+ {error
+ ? (
+ <div className={styles.formLayoutError}>
+ {error}
+ </div>
+ )
+ : null}
+ </div>
</div>
);
};
diff --git a/packages/design/src/components/form-layout/index.module.less b/packages/design/src/components/form-layout/index.module.less
index 5d6d2178d5..6dd58f112c 100644
--- a/packages/design/src/components/form-layout/index.module.less
+++ b/packages/design/src/components/form-layout/index.module.less
@@ -5,7 +5,7 @@
&-label {
font-size: var(--font-size-sm);
min-height: var(--font-size-sm);
- color: rgba(var(--grey-400));
+ color: rgba(var(--color-black));
}
&-desc {
@@ -27,8 +27,23 @@
}
.range-selector {
- width: 100%;
+ width: 100% !important;
+ }
+ }
+
+ &-content-error {
+ .input-affix-wrapper {
+ border: 1px solid rgba(var(--red-400));
}
+
+ .select-single:not(.select-customize-input) .select-selector {
+ border: 1px solid rgba(var(--red-400));
+ }
+ }
+
+ &-error {
+ color: rgba(var(--red-400));
+ font-size: var(--font-size-sm);
}
}
diff --git a/packages/design/src/components/input/Input.tsx b/packages/design/src/components/input/Input.tsx
index a4e20fdd64..fb2d9de0e3 100644
--- a/packages/design/src/components/input/Input.tsx
+++ b/packages/design/src/components/input/Input.tsx
@@ -90,6 +90,7 @@ export interface IInputProps extends Pick<InputProps, 'onFocus' | 'onBlur'> {
* @param value
*/
onChange?: (value: string) => void;
+
}
export function Input(props: IInputProps) {
@@ -119,7 +120,7 @@ export function Input(props: IInputProps) {
[styles.inputAffixWrapperSmall]: size === 'small',
[styles.inputAffixWrapperMiddle]: size === 'middle',
[styles.inputAffixWrapperLarge]: size === 'large',
- });
+ }, className);
return (
<RcInput
diff --git a/packages/design/src/components/popup/RectPopup.tsx b/packages/design/src/components/popup/RectPopup.tsx
index e2a8d83a75..ec5c6be19e 100644
--- a/packages/design/src/components/popup/RectPopup.tsx
+++ b/packages/design/src/components/popup/RectPopup.tsx
@@ -15,6 +15,7 @@
*/
import React, { useEffect, useRef, useState } from 'react';
+import { useEvent } from 'rc-util';
import styles from './index.module.less';
interface IAbsolutePosition {
@@ -35,6 +36,8 @@ export interface IRectPopupProps {
direction?: 'horizontal' | 'vertical';
onClickOutside?: (e: MouseEvent) => void;
+
+ excludeOutside?: HTMLElement[];
}
export interface IPopupLayoutInfo {
@@ -72,12 +75,10 @@ const calcPopupPosition = (layout: IPopupLayoutInfo) => {
};
function RectPopup(props: IRectPopupProps) {
- const { children, anchorRect, direction = 'vertical', onClickOutside } = props;
- const mounted = useRef(false);
+ const { children, anchorRect, direction = 'vertical', onClickOutside, excludeOutside } = props;
const nodeRef = useRef(null);
- const clickOtherFn = useRef(onClickOutside);
+ const clickOtherFn = useEvent(onClickOutside ?? (() => {}));
- clickOtherFn.current = onClickOutside;
const [position, setPosition] = useState<Partial<IAbsolutePosition>>({
top: -9999,
left: -9999,
@@ -99,7 +100,7 @@ function RectPopup(props: IRectPopupProps) {
)
);
},
- // eslint-disable-next-line react-hooks/exhaustive-deps
+ // eslint-disable-next-line react-hooks/exhaustive-deps
[
anchorRect.left,
anchorRect.top,
@@ -109,20 +110,22 @@ function RectPopup(props: IRectPopupProps) {
]);
useEffect(() => {
- mounted.current = true;
const handleClick = (e: MouseEvent) => {
- clickOtherFn.current?.(e);
- };
- setTimeout(() => {
- if (mounted.current) {
- window.addEventListener('click', handleClick);
+ if (excludeOutside && (excludeOutside.indexOf(e.target as any) > -1)) {
+ return;
+ }
+ if (e.clientX <= anchorRect.right && e.clientX >= anchorRect.left && e.clientY <= anchorRect.bottom && e.clientY >= anchorRect.top) {
+ return;
}
- }, 100);
+ clickOtherFn(e);
+ };
+
+ window.addEventListener('click', handleClick);
+
return () => {
- mounted.current = false;
window.removeEventListener('click', handleClick);
};
- }, [clickOtherFn]);
+ }, [anchorRect.bottom, anchorRect.left, anchorRect.right, anchorRect.top, clickOtherFn, excludeOutside]);
return (
<section
diff --git a/packages/design/src/components/select-list/SelectList.stories.tsx b/packages/design/src/components/select-list/SelectList.stories.tsx
index 8cb55c5772..b832bc3451 100644
--- a/packages/design/src/components/select-list/SelectList.stories.tsx
+++ b/packages/design/src/components/select-list/SelectList.stories.tsx
@@ -48,7 +48,7 @@ export const Playground = {
{ label: 'Option 11', value: 'option11' },
];
- function handleChange(value: string | number | boolean) {
+ function handleChange(value: string | string[] | undefined) {
setValue(value as string);
}
diff --git a/packages/design/src/components/select-list/SelectList.tsx b/packages/design/src/components/select-list/SelectList.tsx
index 6ecc370791..be45c53691 100644
--- a/packages/design/src/components/select-list/SelectList.tsx
+++ b/packages/design/src/components/select-list/SelectList.tsx
@@ -24,7 +24,7 @@ export interface ISelectListProps {
/**
* The value of select
*/
- value: string;
+ value: string | string[];
/**
* The options of select
@@ -45,33 +45,54 @@ export interface ISelectListProps {
/**
* The callback function that is triggered when the value is changed
*/
- onChange: (value: string) => void;
+ onChange: (value: string | string[] | undefined) => void;
+
+ multiple?: boolean;
}
export function SelectList(props: ISelectListProps) {
- const { value, options = [], hideCheckMark = false, onChange } = props;
+ const { value: _value, options = [], hideCheckMark = false, onChange, multiple } = props;
+
+ const value = Array.isArray(_value) ? _value : [_value];
+
+ function handleSelect(newValue: string) {
+ const index = value.indexOf(newValue);
- function handleSelect(value: string) {
- onChange(value);
+ if (!multiple) {
+ if (index > -1) {
+ onChange(undefined);
+ } else {
+ onChange(newValue);
+ }
+ } else {
+ if (index > -1) {
+ onChange(value.filter((i) => i === newValue));
+ } else {
+ onChange([...value, newValue]);
+ }
+ }
}
return (
<ul className={styles.selectList}>
- {options.map((option, index) => (
- <li
- key={index}
- className={clsx(styles.selectListItem, { [styles.selectListItemSelect]: value === option.value })}
- >
- <a onClick={() => handleSelect(option.value)}>
- {!hideCheckMark && (
- <span className={styles.selectListItemIcon}>
- {value === option.value && <CheckMarkSingle />}
- </span>
- )}
- <span style={{ color: option.color }}>{option.label}</span>
- </a>
- </li>
- ))}
+ {options.map((option, index) => {
+ const checked = value.indexOf(option.value) > -1;
+ return (
+ <li
+ key={index}
+ className={clsx(styles.selectListItem, { [styles.selectListItemSelect]: checked })}
+ >
+ <a onClick={() => handleSelect(option.value)}>
+ {!hideCheckMark && (
+ <span className={styles.selectListItemIcon}>
+ {checked && <CheckMarkSingle />}
+ </span>
+ )}
+ <span style={{ color: option.color }}>{option.label}</span>
+ </a>
+ </li>
+ );
+ })}
</ul>
);
}
diff --git a/packages/design/src/components/select/Select.tsx b/packages/design/src/components/select/Select.tsx
index 9dac575ad7..52035dcc73 100644
--- a/packages/design/src/components/select/Select.tsx
+++ b/packages/design/src/components/select/Select.tsx
@@ -18,6 +18,7 @@ import { MoreDownSingle } from '@univerjs/icons';
import RcSelect from 'rc-select';
import React, { useContext } from 'react';
+import type { LabelInValueType } from 'rc-select/lib/Select';
import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';
@@ -54,10 +55,33 @@ export interface ISelectProps {
dropdownRender?: (
menu: React.ReactElement<any, string | React.JSXElementConstructor<any>>
) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
+
+ labelRender?: ((props: LabelInValueType) => React.ReactNode) | undefined;
+
+ open?: boolean;
+
+ dropdownStyle?: React.CSSProperties;
+
+ onDropdownVisibleChange?: (open: boolean) => void;
+
+ disabled?: boolean;
}
export function Select(props: ISelectProps) {
- const { value, options = [], onChange, style, className, mode, dropdownRender } = props;
+ const {
+ value,
+ options = [],
+ onChange,
+ style,
+ className,
+ mode,
+ dropdownRender,
+ labelRender,
+ open,
+ dropdownStyle,
+ onDropdownVisibleChange,
+ disabled,
+ } = props;
const { mountContainer } = useContext(ConfigContext);
@@ -74,6 +98,11 @@ export function Select(props: ISelectProps) {
style={style}
className={className}
dropdownRender={dropdownRender}
+ labelRender={labelRender}
+ open={open}
+ dropdownStyle={dropdownStyle}
+ onDropdownVisibleChange={onDropdownVisibleChange}
+ disabled={disabled}
/>
);
}
diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts
index b45583c7bd..d3a3d247d3 100644
--- a/packages/design/src/index.ts
+++ b/packages/design/src/index.ts
@@ -24,6 +24,8 @@ export { ConfigContext, ConfigProvider, type IConfigProviderProps } from './comp
export { Confirm, type IConfirmProps } from './components/confirm';
export { Container, type IContainerProps } from './components/container';
export { DatePicker, type IDatePickerProps } from './components/date-picker';
+export { DatePanel } from './components/date-picker';
+export type { DatePanelProps } from './components/date-picker';
export { Dialog, type IDialogProps } from './components/dialog';
export { Dropdown, type IDropdownProps } from './components/dropdown';
export { FormDualColumnLayout, type IFormDualColumnLayoutProps, FormLayout, type IFormLayoutProps } from './components/form-layout';
diff --git a/packages/engine-formula/src/engine/utils/relative-formula.ts b/packages/engine-formula/src/engine/utils/relative-formula.ts
new file mode 100644
index 0000000000..5cfaa4d2c9
--- /dev/null
+++ b/packages/engine-formula/src/engine/utils/relative-formula.ts
@@ -0,0 +1,62 @@
+/**
+ * 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 { Rectangle, Tools } from '@univerjs/core';
+import type { LexerTreeBuilder } from '../analysis/lexer-tree-builder';
+import { generateStringWithSequence, sequenceNodeType } from './sequence';
+import { deserializeRangeWithSheet, serializeRange } from './reference';
+
+export function isFormulaTransformable(lexerTreeBuilder: LexerTreeBuilder, formula: string) {
+ const originSequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formula);
+ if (!originSequenceNodes) {
+ return false;
+ }
+ // no reference node, return origin formula
+ if (originSequenceNodes.every((node) => typeof node === 'string' || node.nodeType !== sequenceNodeType.REFERENCE)) {
+ return false;
+ }
+
+ return true;
+}
+
+export function transformFormula(lexerTreeBuilder: LexerTreeBuilder, formula: string, originRow: number, originCol: number, targetRow: number, targetCol: number) {
+ if (!isFormulaTransformable(lexerTreeBuilder, formula)) {
+ return formula;
+ }
+
+ const originSequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formula);
+ const getRangeFromCell = (row: number, col: number) => ({ startRow: row, endRow: row, startColumn: col, endColumn: col });
+ const originRange = getRangeFromCell(originRow, originCol);
+
+ const relativeRange = Rectangle.getRelativeRange(getRangeFromCell(targetRow, targetCol), originRange);
+ const sequenceNodes = Tools.deepClone(originSequenceNodes);
+ const transformSequenceNodes = Array.isArray(sequenceNodes)
+ ? sequenceNodes.map((node) => {
+ if (typeof node === 'object' && node.nodeType === sequenceNodeType.REFERENCE) {
+ const gridRangeName = deserializeRangeWithSheet(node.token);
+ const newRange = Rectangle.getPositionRange(relativeRange, gridRangeName.range);
+ const newToken = serializeRange(newRange);
+ return {
+ ...node, token: newToken,
+ };
+ }
+ return node;
+ })
+ : sequenceNodes;
+ const formulaString = transformSequenceNodes && generateStringWithSequence(transformSequenceNodes);
+
+ return `=${formulaString}`;
+}
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts
index 2a27078921..4020abe152 100644
--- a/packages/engine-formula/src/index.ts
+++ b/packages/engine-formula/src/index.ts
@@ -139,6 +139,7 @@ export { SetNumfmtFormulaDataMutation } from './commands/mutations/set-numfmt-fo
export type { ISetNumfmtFormulaDataMutationParams } from './commands/mutations/set-numfmt-formula-data.mutation';
export { isReferenceString } from './basics/regex';
export { matchRefDrawToken } from './basics/match-token';
+export { isFormulaTransformable, transformFormula } from './engine/utils/relative-formula';
export { IDefinedNamesService, DefinedNamesService } from './services/defined-names.service';
export { IFormulaRuntimeService, FormulaRuntimeService } from './services/runtime.service';
export { IFormulaCurrentConfigService, FormulaCurrentConfigService } from './services/current-data.service';
diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.ts
index cd2fc9ab04..71a0fa80f0 100644
--- a/packages/engine-formula/src/services/current-data.service.ts
+++ b/packages/engine-formula/src/services/current-data.service.ts
@@ -153,6 +153,10 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
return this._dirtyUnitFeatureMap;
}
+ getDirtyUnitOtherFormulaMap() {
+ return this._dirtyUnitOtherFormulaMap;
+ }
+
getSheetName(unitId: string, sheetId: string) {
if (this._sheetIdToNameMap[unitId] == null) {
return '';
@@ -161,10 +165,6 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
return this._sheetIdToNameMap[unitId]![sheetId] || '';
}
- getDirtyUnitOtherFormulaMap() {
- return this._dirtyUnitOtherFormulaMap;
- }
-
load(config: IFormulaDatasetConfig) {
if (config.allUnitData && config.unitSheetNameMap) {
this._unitData = config.allUnitData;
diff --git a/packages/engine-render/src/components/sheets/extensions/background.ts b/packages/engine-render/src/components/sheets/extensions/background.ts
index 91605a4186..76e53ee72e 100644
--- a/packages/engine-render/src/components/sheets/extensions/background.ts
+++ b/packages/engine-render/src/components/sheets/extensions/background.ts
@@ -65,7 +65,6 @@ export class Background extends SheetExtension {
ctx.save();
ctx.setGlobalCompositeOperation('destination-over');
-
background &&
Object.keys(background).forEach((rgb: string) => {
const backgroundCache = background[rgb];
diff --git a/packages/engine-render/src/components/sheets/extensions/custom.ts b/packages/engine-render/src/components/sheets/extensions/custom.ts
new file mode 100644
index 0000000000..d239da7634
--- /dev/null
+++ b/packages/engine-render/src/components/sheets/extensions/custom.ts
@@ -0,0 +1,107 @@
+/**
+ * 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 type { IRange, IScale } from '@univerjs/core';
+import { Range, sortRules } from '@univerjs/core';
+import type { UniverRenderingContext } from '../../../context';
+import type { SpreadsheetSkeleton } from '../sheet-skeleton';
+import { SpreadsheetExtensionRegistry } from '../../extension';
+import { SheetExtension } from './sheet-extension';
+
+const UNIQUE_KEY = 'DefaultCustomExtension';
+
+const Z_INDEX = 55;
+
+const stringifyRange = (range: IRange) => {
+ const { startRow, endRow, startColumn, endColumn } = range;
+ return `${startRow}-${endRow}-${startColumn}-${endColumn}`;
+};
+
+export class Custom extends SheetExtension {
+ protected override Z_INDEX = Z_INDEX;
+
+ override uKey: string = UNIQUE_KEY;
+
+ override draw(ctx: UniverRenderingContext, parentScale: IScale, skeleton: SpreadsheetSkeleton, diffRanges?: IRange[] | undefined): void {
+ const { rowHeightAccumulation, columnWidthAccumulation, worksheet, dataMergeCache, rowColumnSegment } = skeleton;
+ if (!worksheet) {
+ return;
+ }
+ const mergeCellRendered = new Set<string>();
+ const subUnitId = worksheet.getSheetId();
+
+ Range.foreach(rowColumnSegment, (row, col) => {
+ let cellData = worksheet.getCell(row, col);
+ if (!cellData?.customRender) {
+ return;
+ }
+
+ let primaryWithCoord = this.getCellIndex(row, col, rowHeightAccumulation, columnWidthAccumulation, dataMergeCache);
+
+ const { mergeInfo } = primaryWithCoord;
+ if (!this.isRenderDiffRangesByRow(mergeInfo.startRow, mergeInfo.endRow, diffRanges)) {
+ return true;
+ }
+
+ if (primaryWithCoord.isMerged || primaryWithCoord.isMergedMainCell) {
+ const rangeStr = stringifyRange(mergeInfo);
+ if (mergeCellRendered.has(rangeStr)) {
+ return;
+ }
+
+ mergeCellRendered.add(rangeStr);
+ }
+
+ if (primaryWithCoord.isMerged) {
+ const mainCell = {
+ row: mergeInfo.startRow,
+ col: mergeInfo.startColumn,
+ };
+ cellData = worksheet.getCell(mainCell.row, mainCell.col);
+ if (!cellData?.customRender) {
+ return;
+ }
+
+ primaryWithCoord = this.getCellIndex(mainCell.row, mainCell.col, rowHeightAccumulation, columnWidthAccumulation, dataMergeCache);
+ }
+
+ const renderInfo = {
+ data: cellData,
+ style: skeleton.getsStyles().getStyleByCell(cellData),
+ primaryWithCoord,
+ subUnitId,
+ row,
+ col,
+ };
+
+ // current cell is hidden
+ if (!worksheet.getColVisible(col) || !worksheet.getRowVisible(row)) {
+ return;
+ }
+
+ const customRender = cellData.customRender.sort(sortRules);
+
+ ctx.save();
+
+ customRender.forEach((item) => {
+ item.drawWith(ctx, renderInfo, skeleton, this.parent);
+ });
+ ctx.restore();
+ });
+ }
+}
+
+SpreadsheetExtensionRegistry.add(Custom);
diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.ts
index 7aaba783de..3edc72b901 100644
--- a/packages/engine-render/src/components/sheets/extensions/font.ts
+++ b/packages/engine-render/src/components/sheets/extensions/font.ts
@@ -67,7 +67,8 @@ export class Font extends SheetExtension {
!rowHeightAccumulation ||
!columnWidthAccumulation ||
columnTotalWidth === undefined ||
- rowTotalHeight === undefined
+ rowTotalHeight === undefined ||
+ !worksheet
) {
return;
}
diff --git a/packages/engine-render/src/components/sheets/extensions/index.ts b/packages/engine-render/src/components/sheets/extensions/index.ts
index 5d2e37df90..d9fabf57e5 100644
--- a/packages/engine-render/src/components/sheets/extensions/index.ts
+++ b/packages/engine-render/src/components/sheets/extensions/index.ts
@@ -20,3 +20,5 @@ export * from './column-header-layout';
export * from './font';
export * from './row-header-layout';
export * from './sheet-extension';
+export * from './marker';
+export * from './custom';
diff --git a/packages/engine-render/src/components/sheets/extensions/marker.ts b/packages/engine-render/src/components/sheets/extensions/marker.ts
new file mode 100644
index 0000000000..f2a9af2134
--- /dev/null
+++ b/packages/engine-render/src/components/sheets/extensions/marker.ts
@@ -0,0 +1,162 @@
+/**
+ * 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 { type IRange, type IScale, Range } from '@univerjs/core';
+import type { UniverRenderingContext } from '../../../context';
+import type { SpreadsheetSkeleton } from '../sheet-skeleton';
+import { SpreadsheetExtensionRegistry } from '../../extension';
+import { SheetExtension } from './sheet-extension';
+
+const UNIQUE_KEY = 'DefaultMarkerExtension';
+
+const Z_INDEX = 60;
+
+const stringifyRange = (range: IRange) => {
+ const { startRow, endRow, startColumn, endColumn } = range;
+ return `${startRow}-${endRow}-${startColumn}-${endColumn}`;
+};
+
+export class Marker extends SheetExtension {
+ protected override Z_INDEX: number = Z_INDEX;
+
+ override uKey: string = UNIQUE_KEY;
+
+ override draw(ctx: UniverRenderingContext, parentScale: IScale, skeleton: SpreadsheetSkeleton, diffRanges?: IRange[] | undefined): void {
+ const { worksheet, rowColumnSegment } = skeleton;
+ if (!worksheet) {
+ return;
+ }
+
+ const mergeCellRendered = new Set<string>();
+
+ Range.foreach(rowColumnSegment, (row, col) => {
+ let cellData = worksheet.getCell(row, col);
+ const cellInfo = this.getCellIndex(
+ row,
+ col,
+ skeleton.rowHeightAccumulation,
+ skeleton.columnWidthAccumulation,
+ skeleton.dataMergeCache
+ );
+ const { isMerged, isMergedMainCell, mergeInfo } = cellInfo;
+ let { startY, endY, startX, endX } = cellInfo;
+
+ if (isMergedMainCell || isMerged) {
+ startY = mergeInfo.startY;
+ endY = mergeInfo.endY;
+ startX = mergeInfo.startX;
+ endX = mergeInfo.endX;
+ }
+
+ if (isMerged) {
+ const mainCell = {
+ row: mergeInfo.startRow,
+ col: mergeInfo.startColumn,
+ };
+
+ cellData = worksheet.getCell(mainCell.row, mainCell.col);
+ }
+
+ if (!this.isRenderDiffRangesByRow(mergeInfo.startRow, mergeInfo.endRow, diffRanges)) {
+ return true;
+ }
+
+ if (cellInfo.isMerged || cellInfo.isMergedMainCell) {
+ const rangeStr = stringifyRange(mergeInfo);
+ if (mergeCellRendered.has(rangeStr)) {
+ return;
+ }
+
+ mergeCellRendered.add(rangeStr);
+ }
+
+ // current cell is hidden
+ if (!worksheet.getColVisible(col) || !worksheet.getRowVisible(row)) {
+ return;
+ }
+
+ if (!cellData) {
+ return;
+ }
+
+ if (cellData.markers?.tr) {
+ ctx.save();
+ const marker = cellData.markers.tr;
+ const x = endX;
+ const y = startY;
+ ctx.fillStyle = marker.color;
+ ctx.moveTo(x, y);
+ ctx.beginPath();
+ ctx.lineTo(x - marker.size, y);
+ ctx.lineTo(x, y + marker.size);
+ ctx.lineTo(x, y);
+ ctx.closePath();
+ ctx.fill();
+ ctx.restore();
+ }
+
+ if (cellData.markers?.tl) {
+ ctx.save();
+ const marker = cellData.markers.tl;
+ const x = startX;
+ const y = startY;
+ ctx.fillStyle = marker.color;
+ ctx.moveTo(x, y);
+ ctx.beginPath();
+ ctx.lineTo(x + marker.size, y);
+ ctx.lineTo(x, y + marker.size);
+ ctx.lineTo(x, y);
+ ctx.closePath();
+ ctx.fill();
+ ctx.restore();
+ }
+
+ if (cellData.markers?.br) {
+ ctx.save();
+ const marker = cellData.markers.br;
+ const x = endX;
+ const y = endY;
+ ctx.fillStyle = marker.color;
+ ctx.moveTo(x, y);
+ ctx.beginPath();
+ ctx.lineTo(x - marker.size, y);
+ ctx.lineTo(x, y - marker.size);
+ ctx.lineTo(x, y);
+ ctx.closePath();
+ ctx.fill();
+ ctx.restore();
+ }
+
+ if (cellData.markers?.bl) {
+ ctx.save();
+ const marker = cellData.markers.bl;
+ const x = startX;
+ const y = endY;
+ ctx.fillStyle = marker.color;
+ ctx.moveTo(x, y);
+ ctx.beginPath();
+ ctx.lineTo(x + marker.size, y);
+ ctx.lineTo(x, y - marker.size);
+ ctx.lineTo(x, y);
+ ctx.closePath();
+ ctx.fill();
+ ctx.restore();
+ }
+ });
+ }
+}
+
+SpreadsheetExtensionRegistry.add(Marker);
diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
index 23c87791f0..f32e9ee83e 100644
--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts
+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
@@ -441,6 +441,7 @@ export class SpreadsheetSkeleton extends Skeleton {
return results;
}
+ // TODO: auto height
private _calculateRowAutoHeight(rowNum: number): number {
const { columnCount, columnData, mergeData, defaultRowHeight } = this._config;
const data = columnData;
@@ -460,12 +461,17 @@ export class SpreadsheetSkeleton extends Skeleton {
continue;
}
const cell = worksheet.getCell(rowNum, i);
+ if (cell?.interceptorAutoHeight) {
+ height = Math.max(height, cell.interceptorAutoHeight);
+ continue;
+ }
+
const modelObject = cell && this._getCellDocumentModel(cell);
if (modelObject == null) {
continue;
}
- const { documentModel, textRotation, wrapStrategy } = modelObject;
+ const { documentModel, textRotation, wrapStrategy, paddingData } = modelObject;
if (documentModel == null) {
continue;
}
diff --git a/packages/engine-render/src/components/sheets/spreadsheet.ts b/packages/engine-render/src/components/sheets/spreadsheet.ts
index 9a3dc365eb..a687351684 100644
--- a/packages/engine-render/src/components/sheets/spreadsheet.ts
+++ b/packages/engine-render/src/components/sheets/spreadsheet.ts
@@ -90,7 +90,6 @@ export class Spreadsheet extends SheetComponent {
}
this._initialDefaultExtension();
-
this.makeDirty(true);
}
@@ -133,7 +132,6 @@ export class Spreadsheet extends SheetComponent {
? bounds?.diffBounds.map((bound) => spreadsheetSkeleton.getRowColumnSegmentByViewBound(bound))
: undefined;
const extensions = this.getExtensionsByOrder();
-
for (const extension of extensions) {
extension.draw(ctx, parentScale, spreadsheetSkeleton, diffRanges);
}
@@ -157,6 +155,10 @@ export class Spreadsheet extends SheetComponent {
if (!spreadsheetSkeleton) {
return;
}
+
+ // this.onPointerDownObserver.add((evt) => {
+ // evt.offsetX;
+ // });
const { rowHeightAccumulation, columnWidthAccumulation, rowHeaderWidth, columnHeaderHeight } =
spreadsheetSkeleton;
diff --git a/packages/engine-render/src/scene.ts b/packages/engine-render/src/scene.ts
index 8aca403f5c..86474270b1 100644
--- a/packages/engine-render/src/scene.ts
+++ b/packages/engine-render/src/scene.ts
@@ -554,7 +554,6 @@ export class Scene extends ThinScene {
// }
coord = this.getRelativeCoord(coord);
-
return this.getActiveViewportByRelativeCoord(coord);
}
diff --git a/packages/engine-render/src/shape/checkbox.ts b/packages/engine-render/src/shape/checkbox.ts
new file mode 100644
index 0000000000..47deca116d
--- /dev/null
+++ b/packages/engine-render/src/shape/checkbox.ts
@@ -0,0 +1,82 @@
+/**
+ * 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 type { IKeyValue } from '@univerjs/core';
+import { Tools } from '@univerjs/core';
+import type { UniverRenderingContext } from '../context';
+import type { IShapeProps } from './shape';
+import { Shape } from './shape';
+
+export interface ICheckboxProps extends IShapeProps {
+ checked?: boolean;
+}
+
+export const CHECK_OBJECT_ARRAY = ['checked'];
+
+export class Checkbox extends Shape<ICheckboxProps> {
+ _checked = false;
+
+ constructor(key: string, props: ICheckboxProps) {
+ super(key, props);
+
+ if (Tools.isDefine(props.checked)) {
+ this._checked = props.checked;
+ }
+ }
+
+ get checked() {
+ return this._checked;
+ }
+
+ static override drawWith(ctx: UniverRenderingContext, props: ICheckboxProps) {
+ const { width = 16, height = 16, fill, checked, top = 0, left = 0 } = props;
+ const uncheckedPath = new Path2D('M12 2.65381H4C3.17157 2.65381 2.5 3.32538 2.5 4.15381V12.1538C2.5 12.9822 3.17157 13.6538 4 13.6538H12C12.8284 13.6538 13.5 12.9822 13.5 12.1538V4.15381C13.5 3.32538 12.8284 2.65381 12 2.65381ZM4 1.65381C2.61929 1.65381 1.5 2.7731 1.5 4.15381V12.1538C1.5 13.5345 2.61929 14.6538 4 14.6538H12C13.3807 14.6538 14.5 13.5345 14.5 12.1538V4.15381C14.5 2.7731 13.3807 1.65381 12 1.65381H4Z');
+ const checkedPath = new Path2D('M3.99243 1.65381C2.61172 1.65381 1.49243 2.77295 1.49243 4.15381V12.1538C1.49243 13.5347 2.61172 14.6538 3.99243 14.6538H11.9924C13.3731 14.6538 14.4924 13.5347 14.4924 12.1538V4.15381C14.4924 2.77295 13.3731 1.65381 11.9924 1.65381H3.99243ZM12.3779 6.3623C12.6317 6.1084 12.6317 5.69678 12.3779 5.44287C12.1241 5.18896 11.7125 5.18896 11.4586 5.44287L7.21062 9.69092L5.00681 7.4873C4.75296 7.2334 4.3414 7.2334 4.08755 7.4873C3.83372 7.74072 3.83372 8.15234 4.08757 8.40625L6.85709 11.1758C7.05234 11.3711 7.36893 11.3711 7.56418 11.1758L12.3779 6.3623Z');
+
+ ctx.save();
+ ctx.translate(left, top);
+ ctx.scale(width / 16, height / 16);
+ if (fill) {
+ ctx.fillStyle = fill;
+ }
+
+ if (checked) {
+ ctx.fill(checkedPath, 'evenodd');
+ } else {
+ ctx.fill(uncheckedPath, 'evenodd');
+ }
+
+ ctx.restore();
+ }
+
+ protected override _draw(ctx: UniverRenderingContext) {
+ Checkbox.drawWith(ctx, this);
+ }
+
+ override toJson() {
+ const props: IKeyValue = {};
+ CHECK_OBJECT_ARRAY.forEach((key) => {
+ if (this[key as keyof Checkbox]) {
+ props[key] = this[key as keyof Checkbox];
+ }
+ });
+
+ return {
+ ...super.toJson(),
+ ...props,
+ };
+ }
+}
diff --git a/packages/engine-render/src/shape/dropdown-item.ts b/packages/engine-render/src/shape/dropdown-item.ts
new file mode 100644
index 0000000000..e83471cf65
--- /dev/null
+++ b/packages/engine-render/src/shape/dropdown-item.ts
@@ -0,0 +1,34 @@
+/**
+ * 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 type { UniverRenderingContext } from '../context';
+import type { IShapeProps } from './shape';
+import { Shape } from './shape';
+
+export interface IListItemProps extends IShapeProps {
+ text: number;
+ fontString: string;
+ fontFamily: string;
+ fontSize: string;
+}
+
+export class ListItem extends Shape<IListItemProps> {
+ static override drawWith(ctx: UniverRenderingContext, props: IListItemProps) {
+ ctx.save();
+
+ ctx.restore();
+ }
+}
diff --git a/packages/engine-render/src/shape/index.ts b/packages/engine-render/src/shape/index.ts
index 466d569ce3..9ed8c3b7ed 100644
--- a/packages/engine-render/src/shape/index.ts
+++ b/packages/engine-render/src/shape/index.ts
@@ -25,3 +25,4 @@ export * from './rich-text';
export * from './scroll-bar';
export * from './selection';
export * from './shape';
+export * from './checkbox';
diff --git a/packages/engine-render/src/shape/text.ts b/packages/engine-render/src/shape/text.ts
new file mode 100644
index 0000000000..f206a1f530
--- /dev/null
+++ b/packages/engine-render/src/shape/text.ts
@@ -0,0 +1,24 @@
+/**
+ * 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 type { IShapeProps } from './shape';
+import { Shape } from './shape';
+
+export interface ITextProps extends IShapeProps {
+ width: number;
+}
+
+export class Text extends Shape<ITextProps> {}
diff --git a/packages/sheets-data-validation/README-zh.md b/packages/sheets-data-validation/README-zh.md
new file mode 100644
index 0000000000..19b95e9a2a
--- /dev/null
+++ b/packages/sheets-data-validation/README-zh.md
@@ -0,0 +1,25 @@
+# @univerjs/sheets-data-validation
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-data-validation)](https://npmjs.org/packages/@univerjs/sheets-data-validation)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-data-validation)](https://img.shields.io/npm/l/@univerjs/sheets-data-validation)
+
+
+## 简介
+
+> `@univerjs/sheets-data-validation` 为 Univer Sheet 提供了完整的数据验证功能。
+
+## 使用指南
+
+### 安装
+
+```shell
+npm i @univerjs/sheets-data-validation
+```
+
+### 注册插件
+
+```typescript
+import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';
+
+univer.registerPlugin(UniverSheetsDataValidationPlugin);
+```
\ No newline at end of file
diff --git a/packages/sheets-data-validation/README.md b/packages/sheets-data-validation/README.md
new file mode 100644
index 0000000000..c04187d15b
--- /dev/null
+++ b/packages/sheets-data-validation/README.md
@@ -0,0 +1,25 @@
+# @univerjs/sheets-data-validation
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-data-validation)](https://npmjs.org/packages/@univerjs/sheets-data-validation)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-data-validation)](https://img.shields.io/npm/l/@univerjs/sheets-data-validation)
+
+
+## Introduction
+
+> `@univerjs/sheets-data-validation` provides full capabilities for Univer Sheet data validation, including panel capabilities.
+
+## Usage
+
+### Installation
+
+```shell
+npm i @univerjs/sheets-data-validation
+```
+
+### Register the plugin
+
+```typescript
+import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';
+
+univer.registerPlugin(UniverSheetsDataValidationPlugin);
+```
\ No newline at end of file
diff --git a/packages/sheets-data-validation/package.json b/packages/sheets-data-validation/package.json
new file mode 100644
index 0000000000..337d7cd29c
--- /dev/null
+++ b/packages/sheets-data-validation/package.json
@@ -0,0 +1,97 @@
+{
+ "name": "@univerjs/sheets-data-validation",
+ "version": "0.1.5",
+ "private": false,
+ "description": "",
+ "author": "univer.ai",
+ "license": "",
+ "keywords": [],
+ "exports": {
+ ".": "./src/index.ts",
+ "./*": "./src/*"
+ },
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/esm/index.js",
+ "types": "./lib/types/index.d.ts",
+ "publishConfig": {
+ "access": "public",
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/es/index.js",
+ "exports": {
+ ".": {
+ "import": "./lib/es/index.js",
+ "require": "./lib/cjs/index.js",
+ "types": "./lib/types/index.d.ts"
+ },
+ "./*": {
+ "import": "./lib/es/*",
+ "require": "./lib/cjs/*",
+ "types": "./lib/types/index.d.ts"
+ }
+ }
+ },
+ "directories": {
+ "lib": "lib"
+ },
+ "files": [
+ "lib"
+ ],
+ "scripts": {
+ "dev": "vite",
+ "test": "vitest run",
+ "test:watch": "vitest",
+ "coverage": "vitest run --coverage",
+ "build": "tsc && vite build"
+ },
+ "peerDependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/data-validation": "workspace:*",
+ "@univerjs/design": "workspace:*",
+ "@univerjs/sheets": "workspace:*",
+ "@univerjs/ui": "workspace:*",
+ "@wendellhu/redi": "^0.13.0",
+ "clsx": ">=2.0.0",
+ "react": ">=16.9.0",
+ "rxjs": ">=7.0.0"
+ },
+ "dependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/data-validation": "workspace:*",
+ "@univerjs/design": "workspace:*",
+ "@univerjs/icons": "^0.1.26",
+ "@univerjs/ui": "workspace:*",
+ "@wendellhu/redi": "^0.13.0",
+ "clsx": "^2.1.0",
+ "dayjs": "^1.11.10",
+ "react": "^18.2.0",
+ "react-draggable-list": "^4.2.0",
+ "rxjs": "^7.8.1"
+ },
+ "devDependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/design": "workspace:*",
+ "@univerjs/docs": "workspace:*",
+ "@univerjs/docs-ui": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
+ "@univerjs/engine-numfmt": "workspace:*",
+ "@univerjs/engine-render": "workspace:*",
+ "@univerjs/network": "workspace:*",
+ "@univerjs/rpc": "workspace:*",
+ "@univerjs/shared": "workspace:*",
+ "@univerjs/sheets": "workspace:*",
+ "@univerjs/sheets-formula": "workspace:*",
+ "@univerjs/sheets-numfmt": "workspace:*",
+ "@univerjs/sheets-ui": "workspace:*",
+ "@univerjs/ui": "workspace:*",
+ "@univerjs/uniscript": "workspace:*",
+ "@vitejs/plugin-react": "^4.2.1",
+ "@vitest/coverage-istanbul": "^1.2.1",
+ "happy-dom": "^13.0.0",
+ "less": "^4.2.0",
+ "typescript": "^5.3.3",
+ "vite": "^5.0.11",
+ "vite-plugin-dts": "^3.7.1",
+ "vite-plugin-externals": "^0.6.2",
+ "vitest": "^1.2.1"
+ }
+}
diff --git a/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts b/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts
new file mode 100644
index 0000000000..ad64d56144
--- /dev/null
+++ b/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts
@@ -0,0 +1,234 @@
+/**
+ * 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 { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, sequenceExecuteAsync } from '@univerjs/core';
+import type { ICommand, IMutationInfo, IRange, ISheetDataValidationRule } from '@univerjs/core';
+import type { IAddDataValidationMutationParams, IUpdateDataValidationMutationParams } from '@univerjs/data-validation';
+import { AddDataValidationMutation, createDefaultNewRule, DataValidationModel, RemoveDataValidationMutation, UpdateDataValidationMutation, UpdateRuleType } from '@univerjs/data-validation';
+import type { SheetDataValidationManager } from '../../models/sheet-data-validation-manager';
+import { OpenValidationPanelOperation } from '../operations/data-validation.operation';
+import type { RangeMutation } from '../../models/rule-matrix';
+
+export interface IUpdateSheetDataValidationRangeCommandParams {
+ unitId: string;
+ subUnitId: string;
+ ruleId: string;
+ ranges: IRange[];
+}
+
+export function getDataValidationDiffMutations(unitId: string, subUnitId: string, diffs: RangeMutation[]) {
+ const redoMutations: IMutationInfo[] = [];
+
+ const undoMutations: IMutationInfo[] = [];
+
+ diffs.forEach((diff) => {
+ switch (diff.type) {
+ case 'delete':
+ redoMutations.push({
+ id: RemoveDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ ruleId: diff.rule.uid,
+ },
+ });
+ undoMutations.unshift({
+ id: AddDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ rule: diff.rule,
+ index: diff.index,
+ },
+ });
+ break;
+ case 'update': {
+ redoMutations.push({
+ id: UpdateDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ ruleId: diff.ruleId,
+ payload: {
+ type: UpdateRuleType.RANGE,
+ payload: diff.newRanges,
+ },
+ } as IUpdateDataValidationMutationParams,
+ });
+ undoMutations.unshift({
+ id: UpdateDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ ruleId: diff.ruleId,
+ payload: {
+ type: UpdateRuleType.RANGE,
+ payload: diff.oldRanges,
+ },
+ } as IUpdateDataValidationMutationParams,
+ });
+ break;
+ }
+ case 'add': {
+ redoMutations.push({
+ id: AddDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ rule: diff.rule,
+ } as IAddDataValidationMutationParams,
+ });
+ undoMutations.unshift({
+ id: RemoveDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ ruleId: diff.rule.uid,
+ },
+ });
+ break;
+ }
+ default:
+ break;
+ }
+ });
+
+ return {
+ redoMutations,
+ undoMutations,
+ };
+}
+
+export const UpdateSheetDataValidationRangeCommand: ICommand<IUpdateSheetDataValidationRangeCommandParams> = {
+ type: CommandType.COMMAND,
+ id: 'sheets.command.updateDataValidationRuleRange',
+ async handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const { unitId, subUnitId, ranges, ruleId } = params;
+ const dataValidationModel = accessor.get(DataValidationModel);
+ const commandService = accessor.get(ICommandService);
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const manager = dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+ const currentRule = manager.getRuleById(ruleId);
+ if (!currentRule) {
+ return false;
+ }
+ const oldRanges = currentRule.ranges;
+ const matrix = manager.getRuleObjectMatrix().clone();
+ matrix.updateRange(ruleId, oldRanges, ranges);
+ const diffs = matrix.diff(manager.getDataValidations());
+
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs);
+
+ undoRedoService.pushUndoRedo({
+ undoMutations,
+ redoMutations,
+ unitID: unitId,
+ });
+ await sequenceExecuteAsync(redoMutations, commandService);
+ return true;
+ },
+};
+
+export interface IAddSheetDataValidationCommandParams {
+ unitId: string;
+ subUnitId: string;
+ rule: ISheetDataValidationRule;
+}
+
+export const AddSheetDataValidationCommand: ICommand<IAddSheetDataValidationCommandParams> = {
+ type: CommandType.COMMAND,
+ id: 'sheets.command.addDataValidation',
+ async handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const { unitId, subUnitId, rule } = params;
+ const dataValidationModel = accessor.get(DataValidationModel);
+ const commandService = accessor.get(ICommandService);
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const manager = dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+
+ const matrix = manager.getRuleObjectMatrix().clone();
+ matrix.addRule(rule);
+ const diffs = matrix.diff(manager.getDataValidations());
+
+ const mutationParams: IAddDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ rule,
+ };
+
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs);
+
+ redoMutations.push({
+ id: AddDataValidationMutation.id,
+ params: mutationParams,
+ });
+
+ undoMutations.unshift({
+ id: RemoveDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ ruleId: rule.uid,
+ },
+ });
+
+ undoRedoService.pushUndoRedo({
+ unitID: unitId,
+ redoMutations,
+ undoMutations,
+ });
+
+ await sequenceExecuteAsync(redoMutations, commandService);
+ return true;
+ },
+};
+
+export const AddSheetDataValidationAndOpenCommand: ICommand = {
+ type: CommandType.COMMAND,
+ id: 'data-validation.command.addRuleAndOpen',
+ async handler(accessor) {
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+ const rule = createDefaultNewRule(accessor);
+ const commandService = accessor.get(ICommandService);
+ const unitId = workbook.getUnitId();
+ const subUnitId = worksheet.getSheetId();
+
+ const addParams: IAddSheetDataValidationCommandParams = {
+ rule,
+ unitId,
+ subUnitId,
+ };
+
+ const res = await commandService.executeCommand(AddSheetDataValidationCommand.id, addParams);
+
+ if (res) {
+ commandService.executeCommand(OpenValidationPanelOperation.id, {
+ ruleId: rule.uid,
+ isAdd: true,
+ });
+
+ return true;
+ }
+ return false;
+ },
+};
diff --git a/packages/sheets-data-validation/src/commands/mutations/formula.mutation.ts b/packages/sheets-data-validation/src/commands/mutations/formula.mutation.ts
new file mode 100644
index 0000000000..88426fce7b
--- /dev/null
+++ b/packages/sheets-data-validation/src/commands/mutations/formula.mutation.ts
@@ -0,0 +1,28 @@
+/**
+ * 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 type { IMutation } from '@univerjs/core';
+import { CommandType } from '@univerjs/core';
+
+export interface IDataValidationFormulaMarkDirtyParams { [unitId: string]: { [sunUnitId: string]: { [formulaId: string]: boolean } } }
+
+export const DataValidationFormulaMarkDirty: IMutation<IDataValidationFormulaMarkDirtyParams> = {
+ type: CommandType.MUTATION,
+ id: 'sheet.mutation.data-validation-formula-mark-dirty',
+ handler() {
+ return true;
+ },
+};
diff --git a/packages/sheets-data-validation/src/commands/operations/data-validation.operation.ts b/packages/sheets-data-validation/src/commands/operations/data-validation.operation.ts
new file mode 100644
index 0000000000..8a307ed08e
--- /dev/null
+++ b/packages/sheets-data-validation/src/commands/operations/data-validation.operation.ts
@@ -0,0 +1,140 @@
+/**
+ * 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 { CommandType, type ICommand, ICommandService, IUniverInstanceService } from '@univerjs/core';
+import { ISidebarService } from '@univerjs/ui';
+import { DataValidationModel } from '@univerjs/data-validation';
+import { DataValidationDropdownManagerService } from '../../services/dropdown-manager.service';
+import { DataValidationPanelService } from '../../services/data-validation-panel.service';
+
+export const DATA_VALIDATION_PANEL = 'DataValidationPanel';
+
+export interface IOpenValidationPanelOperationParams {
+ ruleId?: string;
+ isAdd?: boolean;
+}
+
+export const OpenValidationPanelOperation: ICommand<IOpenValidationPanelOperationParams> = {
+ id: 'data-validation.operation.open-validation-panel',
+ type: CommandType.OPERATION,
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const { ruleId, isAdd } = params;
+ const dataValidationPanelService = accessor.get(DataValidationPanelService);
+ const dataValidationModel = accessor.get(DataValidationModel);
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const sidebarService = accessor.get(ISidebarService);
+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+ const unitId = workbook.getUnitId();
+ const subUnitId = worksheet.getSheetId();
+ const rule = ruleId ? dataValidationModel.getRuleById(unitId, subUnitId, ruleId) : undefined;
+ dataValidationPanelService.open();
+ dataValidationPanelService.setActiveRule(rule && {
+ unitId,
+ subUnitId,
+ rule,
+ });
+ sidebarService.open({
+ header: { title: isAdd ? 'dataValidation.panel.addTitle' : 'dataValidation.panel.title' },
+ children: { label: DATA_VALIDATION_PANEL },
+ width: 312,
+ });
+ return true;
+ },
+};
+
+export const CloseValidationPanelOperation: ICommand = {
+ id: 'data-validation.operation.close-validation-panel',
+ type: CommandType.OPERATION,
+ handler(accessor) {
+ const dataValidationPanelService = accessor.get(DataValidationPanelService);
+ dataValidationPanelService.close();
+ return true;
+ },
+};
+
+export const ToggleValidationPanelOperation: ICommand = {
+ id: 'data-validation.operation.toggle-validation-panel',
+ type: CommandType.OPERATION,
+ handler(accessor) {
+ const commandService = accessor.get(ICommandService);
+ const dataValidationPanelService = accessor.get(DataValidationPanelService);
+ dataValidationPanelService.open();
+ const isOpen = dataValidationPanelService.isOpen;
+
+ if (isOpen) {
+ commandService.executeCommand(CloseValidationPanelOperation.id);
+ } else {
+ commandService.executeCommand(OpenValidationPanelOperation.id);
+ }
+ return true;
+ },
+};
+
+export interface IShowDataValidationDropdownParams {
+ unitId: string;
+ subUnitId: string;
+ row: number;
+ column: number;
+}
+
+export const ShowDataValidationDropdown: ICommand<IShowDataValidationDropdownParams> = {
+ type: CommandType.OPERATION,
+ id: 'sheet.operation.show-data-validation-dropdown',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const dataValidationDropdownManagerService = accessor.get(DataValidationDropdownManagerService);
+ const { unitId, subUnitId, row, column } = params;
+
+ const activeDropdown = dataValidationDropdownManagerService.activeDropdown;
+ const currLoc = activeDropdown?.location;
+ if (
+ currLoc &&
+ currLoc.unitId === unitId &&
+ currLoc.subUnitId === subUnitId &&
+ currLoc.row === row &&
+ currLoc.col === column
+ ) {
+ return true;
+ }
+
+ dataValidationDropdownManagerService.showDataValidationDropdown(
+ unitId,
+ subUnitId,
+ row,
+ column
+ );
+ return true;
+ },
+};
+
+export const HideDataValidationDropdown: ICommand = {
+ type: CommandType.OPERATION,
+ id: 'sheet.operation.hide-data-validation-dropdown',
+ handler(accessor, params) {
+ if (!params) {
+ return false;
+ }
+ const dataValidationDropdownManagerService = accessor.get(DataValidationDropdownManagerService);
+ dataValidationDropdownManagerService.hideDropdown();
+ return true;
+ },
+};
diff --git a/packages/sheets-data-validation/src/common/const.ts b/packages/sheets-data-validation/src/common/const.ts
new file mode 100644
index 0000000000..f461690346
--- /dev/null
+++ b/packages/sheets-data-validation/src/common/const.ts
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+export const DATA_VALIDATION_PLUGIN_NAME = 'SHEET_DATA_VALIDATION';
+
+export const DROP_DOWN_DEFAULT_COLOR = '#ECECEC';
+
+export const DROP_DOWN_COLORS = [];
diff --git a/packages/sheets-data-validation/src/controllers/dv-alert.controller.ts b/packages/sheets-data-validation/src/controllers/dv-alert.controller.ts
new file mode 100644
index 0000000000..8b5cff0dae
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-alert.controller.ts
@@ -0,0 +1,85 @@
+/**
+ * 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 { DataValidationStatus, Disposable, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';
+import { CellAlertManagerService, CellAlertType, HoverManagerService } from '@univerjs/sheets-ui';
+import { Inject } from '@wendellhu/redi';
+import { SheetDataValidationService } from '../services/dv.service';
+
+@OnLifecycle(LifecycleStages.Rendered, DataValidationAlertController)
+export class DataValidationAlertController extends Disposable {
+ constructor(
+ @Inject(HoverManagerService) private readonly _hoverManagerService: HoverManagerService,
+ @Inject(CellAlertManagerService) private readonly _cellAlertManagerService: CellAlertManagerService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(SheetDataValidationService) private readonly _sheetDataValidationService: SheetDataValidationService,
+ @Inject(LocaleService) private readonly _localeService: LocaleService
+ ) {
+ super();
+ this._init();
+ }
+
+ private _init() {
+ this._initCellAlertPopup();
+ }
+
+ private _initCellAlertPopup() {
+ this.disposeWithMe(this._hoverManagerService.currentCell$.subscribe((cellPos) => {
+ if (cellPos) {
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+ const manager = this._sheetDataValidationService.currentManager?.manager;
+ const cellData = worksheet.getCell(cellPos.location.row, cellPos.location.col);
+
+ if (cellData?.dataValidation?.validStatus === DataValidationStatus.INVALID) {
+ const currentLoc = this._cellAlertManagerService.currentAlert?.location;
+ if (
+ currentLoc &&
+ currentLoc.row === cellPos.location.row &&
+ currentLoc.col === cellPos.location.col &&
+ currentLoc.subUnitId === cellPos.location.subUnitId &&
+ currentLoc.unitId === cellPos.location.unitId
+ ) {
+ return;
+ }
+ this._cellAlertManagerService.showAlert({
+ type: CellAlertType.ERROR,
+ title: this._localeService.t('dataValidation.error.title'),
+ message: manager?.getRuleErrorMsg(cellData.dataValidation.ruleId),
+ location: cellPos.location,
+ width: 200,
+ height: 74,
+ });
+ return;
+ }
+
+ // if (cellData?.dataValidation?.rule.showInputMessage) {
+ // this._cellAlertManagerService.showAlert({
+ // type: CellAlertType.INFO,
+ // title: this._localeService.t('dataValidation.error.title'),
+ // message: manager?.getRuleErrorMsg(cellData.dataValidation.ruleId),
+ // location: cellPos.location,
+ // width: 200,
+ // height: 74,
+ // });
+ // return;
+ // }
+ }
+
+ this._cellAlertManagerService.clearAlert();
+ }));
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv-auto-fill.controller.ts b/packages/sheets-data-validation/src/controllers/dv-auto-fill.controller.ts
new file mode 100644
index 0000000000..676c7a6f4f
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-auto-fill.controller.ts
@@ -0,0 +1,114 @@
+/**
+ * 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 { Disposable, LifecycleStages, OnLifecycle, Range, Rectangle } from '@univerjs/core';
+import type { ISheetAutoFillHook } from '@univerjs/sheets-ui';
+import { APPLY_TYPE, getAutoFillRepeatRange, IAutoFillService } from '@univerjs/sheets-ui';
+import { Inject } from '@wendellhu/redi';
+import { DataValidationModel } from '@univerjs/data-validation';
+import type { IAutoFillLocation } from '@univerjs/sheets-ui/services/auto-fill/type.js';
+import { DATA_VALIDATION_PLUGIN_NAME } from '../common/const';
+import type { SheetDataValidationManager } from '../models/sheet-data-validation-manager';
+import { getDataValidationDiffMutations } from '../commands/commands/data-validation.command';
+
+@OnLifecycle(LifecycleStages.Ready, DataValidationAutoFillController)
+export class DataValidationAutoFillController extends Disposable {
+ constructor(
+ @IAutoFillService private readonly _autoFillService: IAutoFillService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel
+ ) {
+ super();
+ this._initAutoFill();
+ }
+
+ private _initAutoFill() {
+ const noopReturnFunc = () => ({ redos: [], undos: [] });
+
+ const generalApplyFunc = (location: IAutoFillLocation) => {
+ const { source: sourceRange, target: targetRange, unitId, subUnitId } = location;
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+ const ruleMatrixCopy = manager.getRuleObjectMatrix().clone();
+ const sourceStartCell = {
+ row: sourceRange.startRow,
+ col: sourceRange.startColumn,
+ };
+
+ const repeats = getAutoFillRepeatRange(sourceRange, targetRange);
+ repeats.forEach((repeat) => {
+ const targetStartCell = repeat.repeatStartCell;
+ const relativeRange = repeat.relativeRange;
+ const sourceRange = {
+ startRow: sourceStartCell.row,
+ startColumn: sourceStartCell.col,
+ endColumn: sourceStartCell.col,
+ endRow: sourceStartCell.row,
+ };
+ const targetRange = {
+ startRow: targetStartCell.row,
+ startColumn: targetStartCell.col,
+ endColumn: targetStartCell.col,
+ endRow: targetStartCell.row,
+ };
+ Range.foreach(relativeRange, (row, col) => {
+ const sourcePositionRange = Rectangle.getPositionRange(
+ {
+ startRow: row,
+ startColumn: col,
+ endColumn: col,
+ endRow: row,
+ },
+ sourceRange
+ );
+ const ruleId = manager.getRuleIdByLocation(sourcePositionRange.startRow, sourcePositionRange.startColumn);
+ if (ruleId) {
+ const targetPositionRange = Rectangle.getPositionRange(
+ {
+ startRow: row,
+ startColumn: col,
+ endColumn: col,
+ endRow: row,
+ },
+ targetRange
+ );
+ ruleMatrixCopy.setValue(targetPositionRange.startRow, targetPositionRange.startColumn, ruleId);
+ }
+ });
+ });
+
+ const diffs = ruleMatrixCopy.diff(manager.getDataValidations());
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs);
+ return {
+ undos: undoMutations,
+ redos: redoMutations,
+ };
+ };
+ const hook: ISheetAutoFillHook = {
+ id: DATA_VALIDATION_PLUGIN_NAME,
+ onFillData: (location, direction, applyType) => {
+ if (
+ applyType === APPLY_TYPE.COPY ||
+ applyType === APPLY_TYPE.ONLY_FORMAT ||
+ applyType === APPLY_TYPE.SERIES
+ ) {
+ return generalApplyFunc(location);
+ }
+
+ return noopReturnFunc();
+ },
+ };
+ this.disposeWithMe(this._autoFillService.addHook(hook));
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv-copy-paste.controller.ts b/packages/sheets-data-validation/src/controllers/dv-copy-paste.controller.ts
new file mode 100644
index 0000000000..9938aa3aa2
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-copy-paste.controller.ts
@@ -0,0 +1,189 @@
+/**
+ * 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 type { IRange, ISheetDataValidationRule, Nullable } from '@univerjs/core';
+import { Disposable, LifecycleStages, ObjectMatrix, OnLifecycle, Range, Rectangle } from '@univerjs/core';
+import { COPY_TYPE, getRepeatRange, ISheetClipboardService, PREDEFINED_HOOK_NAME } from '@univerjs/sheets-ui';
+import { Inject } from '@wendellhu/redi';
+import { DataValidationModel } from '@univerjs/data-validation';
+import { SPECIAL_PASTE_FORMULA } from '@univerjs/sheets-formula/commands/commands/formula-clipboard.command.js';
+import type { SheetDataValidationManager } from '../models/sheet-data-validation-manager';
+import { DATA_VALIDATION_PLUGIN_NAME } from '../common/const';
+import { getDataValidationDiffMutations } from '../commands/commands/data-validation.command';
+
+@OnLifecycle(LifecycleStages.Ready, DataValidationCopyPasteController)
+export class DataValidationCopyPasteController extends Disposable {
+ private _copyInfo: Nullable<{
+ matrix: ObjectMatrix<string>;
+ unitId: string;
+ subUnitId: string;
+ }>;
+
+ constructor(
+ @ISheetClipboardService private _sheetClipboardService: ISheetClipboardService,
+ @Inject(DataValidationModel) private _dataValidationModel: DataValidationModel
+ ) {
+ super();
+ this._initCopyPaste();
+ }
+
+ private _initCopyPaste() {
+ this._sheetClipboardService.addClipboardHook({
+ id: DATA_VALIDATION_PLUGIN_NAME,
+ onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
+ onPasteCells: (pasteFrom, pasteTo, data, payload) => {
+ const { copyType = COPY_TYPE.COPY, pasteType } = payload;
+ const { range: copyRange } = pasteFrom || {};
+ const { range: pastedRange, unitId, subUnitId } = pasteTo;
+ return this._generateMutations(pastedRange, { copyType, pasteType, copyRange, unitId, subUnitId });
+ },
+ });
+ }
+
+ private _collect(unitId: string, subUnitId: string, range: IRange) {
+ const matrix = new ObjectMatrix<string>();
+ this._copyInfo = {
+ unitId,
+ subUnitId,
+ matrix,
+ };
+
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+
+ Range.foreach(range, (row, col) => {
+ const ruleId = manager.getRuleIdByLocation(row, col);
+
+ const relativeRange = Rectangle.getRelativeRange(
+ {
+ startRow: row,
+ endRow: row,
+ startColumn: col,
+ endColumn: col,
+ },
+ range
+ );
+ matrix.setValue(relativeRange.startRow, relativeRange.startColumn, ruleId ?? '');
+ });
+ }
+
+ private _generateMutations(
+ pastedRange: IRange,
+ copyInfo: {
+ copyType: COPY_TYPE;
+ copyRange?: IRange;
+ pasteType: string;
+ unitId: string;
+ subUnitId: string;
+ }
+ ) {
+ if (!this._copyInfo) {
+ return { redos: [], undos: [] };
+ }
+ if (copyInfo.copyType === COPY_TYPE.CUT) {
+ this._copyInfo = null;
+ return { redos: [], undos: [] };
+ }
+ if (!this._copyInfo || !this._copyInfo.matrix.getSizeOf() || !copyInfo.copyRange) {
+ return { redos: [], undos: [] };
+ }
+
+ if (
+ [
+ PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,
+ PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,
+ PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,
+ SPECIAL_PASTE_FORMULA,
+ ].includes(
+ copyInfo.pasteType
+ )
+ ) {
+ return { redos: [], undos: [] };
+ }
+
+ const { unitId, subUnitId } = this._copyInfo;
+
+ if (copyInfo.unitId !== unitId || subUnitId !== copyInfo.subUnitId) {
+ const originManager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+ const manager = this._dataValidationModel.ensureManager(copyInfo.unitId, copyInfo.subUnitId) as SheetDataValidationManager;
+ const ruleMatrix = manager.getRuleObjectMatrix().clone();
+ const repeatRange = getRepeatRange(copyInfo.copyRange, pastedRange, true);
+ const additionRules: Map<string, ISheetDataValidationRule> = new Map();
+
+ repeatRange.forEach(({ startRange }) => {
+ this._copyInfo?.matrix.forValue((row, col, ruleId) => {
+ const range = Rectangle.getPositionRange(
+ {
+ startRow: row,
+ endRow: row,
+ startColumn: col,
+ endColumn: col,
+ },
+ startRange
+ );
+ const transformedRuleId = `${subUnitId}-${ruleId}`;
+ const oldRule = originManager.getRuleById(ruleId);
+
+ if (!manager.getRuleById(transformedRuleId) && oldRule) {
+ additionRules.set(transformedRuleId, { ...oldRule, uid: transformedRuleId });
+ }
+
+ ruleMatrix.setValue(range.startRow, range.startColumn, transformedRuleId);
+ });
+ });
+
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(
+ copyInfo.unitId,
+ copyInfo.subUnitId,
+ ruleMatrix.diffWithAddition(manager.getDataValidations(), additionRules.values())
+ );
+
+ return {
+ redos: redoMutations,
+ undos: undoMutations,
+ };
+ } else {
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+ const ruleMatrix = manager.getRuleObjectMatrix().clone();
+ const repeatRange = getRepeatRange(copyInfo.copyRange, pastedRange, true);
+
+ repeatRange.forEach(({ startRange }) => {
+ this._copyInfo?.matrix.forValue((row, col, ruleId) => {
+ const range = Rectangle.getPositionRange(
+ {
+ startRow: row,
+ endRow: row,
+ startColumn: col,
+ endColumn: col,
+ },
+ startRange
+ );
+ ruleMatrix.setValue(range.startRow, range.startColumn, ruleId);
+ });
+ });
+
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(
+ unitId,
+ subUnitId,
+ ruleMatrix.diff(manager.getDataValidations())
+ );
+
+ return {
+ redos: redoMutations,
+ undos: undoMutations,
+ };
+ }
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts b/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts
new file mode 100644
index 0000000000..ebf59935f4
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-ref-range.controller.ts
@@ -0,0 +1,397 @@
+/**
+ * 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 type { IRange, ISheetDataValidationRule } from '@univerjs/core';
+import { DataValidationType, Disposable, DisposableCollection, ICommandService, isRangesEqual, IUniverInstanceService, LifecycleStages, OnLifecycle, Range, Rectangle, toDisposable } from '@univerjs/core';
+import type { EffectRefRangeParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';
+import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';
+import { handleDefaultRangeChangeWithEffectRefCommands, handleOtherDefaultRangeChangeWithEffectRefCommands, RefRangeService, SetRangeValuesMutation } from '@univerjs/sheets';
+import { Inject, Injector } from '@wendellhu/redi';
+import { merge, Observable } from 'rxjs';
+import { distinctUntilChanged, map, switchMap } from 'rxjs/operators';
+import type { IRemoveDataValidationMutationParams, IUpdateDataValidationMutationParams } from '@univerjs/data-validation';
+import { DataValidationModel, RemoveDataValidationMutation, UpdateDataValidationMutation, UpdateRuleType } from '@univerjs/data-validation';
+import { removeDataValidationUndoFactory } from '@univerjs/data-validation/commands/commands/data-validation.command.js';
+import { FormulaRefRangeService } from '@univerjs/sheets-formula';
+import { deserializeRangeWithSheet, isReferenceString, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';
+import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+import { DataValidationCacheService } from '../services/dv-cache.service';
+
+@OnLifecycle(LifecycleStages.Rendered, DataValidationRefRangeController)
+export class DataValidationRefRangeController extends Disposable {
+ private _disposableMap: Map<string, Set<() => void>> = new Map();
+
+ constructor(
+ @Inject(DataValidationModel) private _dataValidationModel: DataValidationModel,
+ @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,
+ @Inject(Injector) private _injector: Injector,
+ @Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService,
+ @Inject(RefRangeService) private _refRangeService: RefRangeService,
+ @Inject(DataValidationCustomFormulaService) private _dataValidationCustomFormulaService: DataValidationCustomFormulaService,
+ @Inject(DataValidationFormulaService) private _dataValidationFormulaService: DataValidationFormulaService,
+ @Inject(FormulaRefRangeService) private _formulaRefRangeService: FormulaRefRangeService,
+ @ICommandService private readonly _commandService: ICommandService,
+ @Inject(DataValidationCacheService) private readonly _dataValidationCacheService: DataValidationCacheService
+ ) {
+ super();
+ this._initRefRange();
+ }
+
+ private _getIdWithUnitId(unitID: string, subUnitId: string, ruleId: string) {
+ return `${unitID}_${subUnitId}_${ruleId}`;
+ }
+
+ registerFormula(unitId: string, subUnitId: string, rule: ISheetDataValidationRule) {
+ const ruleId = rule.uid;
+ const id = this._getIdWithUnitId(unitId, subUnitId, ruleId);
+ const disposeSet = this._disposableMap.get(id) ?? new Set();
+ const handleFormulaChange = (type: 'formula1' | 'formula2', formulaString: string) => {
+ const oldRule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
+ if (!oldRule) {
+ return { redos: [], undos: [] };
+ }
+ const oldFormula = oldRule[type];
+ if (!oldFormula || oldFormula === formulaString) {
+ return { redos: [], undos: [] };
+ }
+ const redoParams: IUpdateDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId: rule.uid,
+ payload: {
+ type: UpdateRuleType.SETTING,
+ payload: {
+ type: oldRule.type,
+ formula1: oldRule.formula1,
+ formula2: oldRule.formula2,
+ [type]: formulaString,
+ },
+ },
+ };
+ const undoParams: IUpdateDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId: rule.uid,
+ payload: {
+ type: UpdateRuleType.SETTING,
+ payload: {
+ type: oldRule.type,
+ formula1: oldRule.formula1,
+ formula2: oldRule.formula2,
+ [type]: formulaString,
+ },
+ },
+ };
+ const redos = [
+ {
+ id: UpdateDataValidationMutation.id,
+ params: redoParams,
+ },
+ ];
+ const undos = [
+ {
+ id: UpdateDataValidationMutation.id,
+ params: undoParams,
+ },
+ ];
+ return { redos, undos };
+ };
+
+ if (rule.type === DataValidationType.CUSTOM) {
+ const currentFormula = this._dataValidationCustomFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
+ if (currentFormula) {
+ const disposable = this._formulaRefRangeService.registerFormula(
+ currentFormula.formula,
+ (newFormulaString) => handleFormulaChange('formula1', newFormulaString)
+ );
+ disposeSet.add(() => disposable.dispose());
+ }
+ }
+
+ if (rule.type !== DataValidationType.CUSTOM) {
+ const currentFormula = this._dataValidationFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
+ if (currentFormula) {
+ const [formula1, formula2] = currentFormula;
+ if (formula1) {
+ const disposable = this._formulaRefRangeService.registerFormula(
+ formula1.text,
+ (newFormulaString) => handleFormulaChange('formula1', newFormulaString)
+ );
+ disposeSet.add(() => disposable.dispose());
+ }
+
+ if (formula2) {
+ const disposable = this._formulaRefRangeService.registerFormula(
+ formula2.text,
+ (newFormulaString) => handleFormulaChange('formula1', newFormulaString)
+ );
+ disposeSet.add(() => disposable.dispose());
+ }
+ }
+ }
+ }
+
+ register(unitId: string, subUnitId: string, rule: ISheetDataValidationRule) {
+ const handleRangeChange = (commandInfo: EffectRefRangeParams) => {
+ const oldRanges = [...rule.ranges];
+ const resultRangesOrigin = oldRanges.map((range) => {
+ return handleOtherDefaultRangeChangeWithEffectRefCommands(range, commandInfo) as IRange | IRange[];
+ }).filter((range) => !!range);
+
+ const resultRanges = resultRangesOrigin.flat();
+
+ const isEqual = isRangesEqual(resultRanges, oldRanges);
+ if (isEqual) {
+ return { redos: [], undos: [] };
+ }
+
+ if (resultRanges.length) {
+ const redoParams: IUpdateDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId: rule.uid,
+ payload: {
+ type: UpdateRuleType.RANGE,
+ payload: resultRanges,
+ },
+ };
+ // in ref-range case, there won't be any overlap about rule ranges
+ const redos = [{ id: UpdateDataValidationMutation.id, params: redoParams }];
+ const undos = [{
+ id: UpdateDataValidationMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ ruleId: rule.uid,
+ payload: {
+ type: UpdateRuleType.RANGE,
+ payload: oldRanges,
+ },
+ },
+ }];
+ return { redos, undos };
+ } else {
+ const redoParams: IRemoveDataValidationMutationParams = { unitId, subUnitId, ruleId: rule.uid };
+ const redos = [{ id: RemoveDataValidationMutation.id, params: redoParams }];
+ const undos = removeDataValidationUndoFactory(this._injector, redoParams);
+ return { redos, undos };
+ }
+ };
+ const disposeList: (() => void)[] = [];
+ rule.ranges.forEach((range) => {
+ const disposable = this._refRangeService.registerRefRange(range, handleRangeChange);
+ disposeList.push(() => disposable.dispose());
+ });
+
+ const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid);
+ const current = this._disposableMap.get(id) ?? new Set();
+ current.add(() => disposeList.forEach((dispose) => dispose()));
+ this._disposableMap.set(id, current);
+ };
+
+ registerRange(propUnitId: string, propSubUnitId: string, rule: ISheetDataValidationRule) {
+ const { uid: ruleId, formula1, type } = rule;
+ if ((type !== DataValidationType.LIST && type !== DataValidationType.LIST_MULTIPLE)) {
+ return;
+ }
+
+ if (!isReferenceString(formula1 ?? '')) {
+ return;
+ }
+ const gridRange = deserializeRangeWithSheet(formula1 ?? '');
+ const id = this._getIdWithUnitId(propUnitId, propSubUnitId, ruleId);
+ const rangeUnitId = gridRange.unitId || propUnitId;
+ const workbook = this._univerInstanceService.getUniverSheetInstance(rangeUnitId) ?? this._univerInstanceService.getCurrentUniverSheetInstance();
+ const sheetId = workbook.getSheetBySheetName(gridRange.sheetName)?.getSheetId() ?? propSubUnitId;
+ const worksheet = workbook.getSheetBySheetId(sheetId) ?? workbook.getActiveSheet();
+ const disposableCollection = new DisposableCollection();
+ const range = gridRange.range;
+
+ const finalUnitId = workbook.getUnitId();
+ const finalSubUnitId = worksheet.getSheetId();
+
+ disposableCollection.add(
+ this._refRangeService.registerRefRange(
+ range,
+ (info) => {
+ let newRange = handleDefaultRangeChangeWithEffectRefCommands(range, info);
+ if (!newRange) {
+ newRange = {
+ startColumn: -1,
+ endColumn: -1,
+ startRow: -1,
+ endRow: -1,
+ };
+ }
+
+ if (Rectangle.equals(newRange, range)) {
+ return {
+ redos: [],
+ undos: [],
+ };
+ }
+
+ const newRangeStr = serializeRangeWithSpreadsheet(finalUnitId, finalSubUnitId, newRange);
+ const oldRule = this._dataValidationModel.getRuleById(propUnitId, propSubUnitId, ruleId);
+ if (!oldRule) {
+ return {
+ redos: [],
+ undos: [],
+ };
+ }
+ const redoParams: IUpdateDataValidationMutationParams = {
+ unitId: propUnitId,
+ subUnitId: propSubUnitId,
+ ruleId,
+ payload: {
+ type: UpdateRuleType.SETTING,
+ payload: {
+ formula1: newRangeStr,
+ formula2: oldRule.formula2,
+ type: oldRule.type,
+ },
+ },
+ };
+ const undoParams: IUpdateDataValidationMutationParams = {
+ unitId: propUnitId,
+ subUnitId: propSubUnitId,
+ ruleId,
+ payload: {
+ type: UpdateRuleType.SETTING,
+ payload: {
+ formula1: oldRule.formula1,
+ formula2: oldRule.formula2,
+ type: oldRule.type,
+ },
+ },
+ };
+
+ return {
+ redos: [{
+ id: UpdateDataValidationMutation.id,
+ params: redoParams,
+ }],
+ undos: [{
+ id: UpdateDataValidationMutation.id,
+ params: undoParams,
+ }],
+ };
+ },
+ finalUnitId,
+ finalUnitId
+ )
+ );
+
+ disposableCollection.add(this.disposeWithMe(
+ this._commandService.onCommandExecuted((commandInfo) => {
+ if (commandInfo.id === SetRangeValuesMutation.id && commandInfo.params) {
+ const params = commandInfo.params as ISetRangeValuesMutationParams;
+ const {
+ cellValue,
+ unitId,
+ subUnitId,
+ } = params;
+
+ if (unitId === finalUnitId && subUnitId === finalSubUnitId) {
+ if (cellValue) {
+ let marked = false;
+
+ Range.foreach(range, (row, col) => {
+ const rowValue = cellValue[row];
+ if (rowValue && (col in rowValue)) {
+ if (marked) {
+ return;
+ }
+ marked = true;
+ this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
+ }
+ });
+ } else {
+ this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
+ }
+ }
+ }
+ })
+ ));
+
+ const current = this._disposableMap.get(id) ?? new Set();
+ current.add(() => disposableCollection.dispose());
+ this._disposableMap.set(id, current);
+ }
+
+ private _initRefRange() {
+ this.disposeWithMe(
+ merge(
+ this._sheetSkeletonManagerService.currentSkeleton$.pipe(
+ map((skeleton) => skeleton?.sheetId),
+ distinctUntilChanged()
+ )
+ )
+ .pipe(
+ switchMap(
+ () =>
+ new Observable<DisposableCollection>((subscribe) => {
+ const disposableCollection = new DisposableCollection();
+ subscribe.next(disposableCollection);
+ return () => {
+ disposableCollection.dispose();
+ };
+ })
+ )
+ ).subscribe((disposableCollection) => {
+ disposableCollection.add(
+ toDisposable(
+ this._dataValidationModel.ruleChange$.subscribe((option) => {
+ const { unitId, subUnitId, rule } = option;
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+ if (option.unitId !== workbook.getUnitId() || option.subUnitId !== worksheet.getSheetId()) {
+ return;
+ }
+ switch (option.type) {
+ case 'add': {
+ const rule = option.rule!;
+ this.register(option.unitId, option.subUnitId, rule);
+ this.registerFormula(option.unitId, option.subUnitId, rule);
+ this.registerRange(option.unitId, option.subUnitId, rule);
+ break;
+ }
+ case 'remove': {
+ const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule!.uid));
+ disposeSet && disposeSet.forEach((dispose) => dispose());
+ break;
+ }
+ case 'update': {
+ const rule = option.rule!;
+ const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule!.uid));
+ disposeSet && disposeSet.forEach((dispose) => dispose());
+ this.register(option.unitId, option.subUnitId, rule);
+ this.registerFormula(option.unitId, option.subUnitId, rule);
+ this.registerRange(option.unitId, option.subUnitId, rule);
+ }
+ }
+ })));
+ }));
+
+ this.disposeWithMe(toDisposable(() => {
+ this._disposableMap.forEach((item) => {
+ item.forEach((dispose) => dispose());
+ });
+ this._disposableMap.clear();
+ }));
+ }
+}
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.ts
new file mode 100644
index 0000000000..7800b40206
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-reject-input.controller.ts
@@ -0,0 +1,103 @@
+/**
+ * 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 { DataValidationErrorStyle, Disposable, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';
+import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
+import { IEditorBridgeService } from '@univerjs/sheets-ui';
+import { Inject } from '@wendellhu/redi';
+import { IDialogService } from '@univerjs/ui';
+import React from 'react';
+import { Button } from '@univerjs/design';
+import type { SheetDataValidationManager } from '../models/sheet-data-validation-manager';
+import { getCellValueOrigin } from '../utils/get-cell-data-origin';
+
+@OnLifecycle(LifecycleStages.Ready, DataValidationRejectInputController)
+export class DataValidationRejectInputController extends Disposable {
+ constructor(
+ @IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
+ @Inject(DataValidatorRegistryService) private readonly _dataValidatorRegistryService: DataValidatorRegistryService,
+ @IDialogService private readonly _dialogService: IDialogService,
+ @Inject(LocaleService) private readonly _localeService: LocaleService
+ ) {
+ super();
+ this._initEditorBridgeInterceptor();
+ }
+
+ private _initEditorBridgeInterceptor() {
+ this._editorBridgeService.interceptor.intercept(
+ this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT_ASYNC,
+ {
+ handler: async (cellPromise, context, next) => {
+ const cell = await cellPromise;
+ const { worksheet, row, col, unitId, subUnitId } = context;
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+ const ruleId = manager.getRuleIdByLocation(row, col);
+ const rule = ruleId ? manager.getRuleById(ruleId) : undefined;
+ if (!rule || rule.errorStyle !== DataValidationErrorStyle.STOP) {
+ return next(Promise.resolve(cell));
+ }
+
+ const validator = await this._dataValidatorRegistryService.getValidatorItem(rule.type);
+ if (!validator) {
+ return next(Promise.resolve(cell));
+ }
+
+ const cellRaw = context.worksheet.getCellRaw(context.row, context.col);
+ const success = await validator.validator(
+ {
+ value: getCellValueOrigin(cellRaw),
+ row,
+ column: col,
+ unitId,
+ subUnitId,
+ }, rule
+ );
+
+ if (success) {
+ return next(Promise.resolve(cell));
+ }
+
+ const oldCell = worksheet.getCellRaw(row, col);
+ this._dialogService.open({
+ width: 368,
+ title: {
+ title: this._localeService.t('dataValidation.alert.title'),
+ },
+ id: 'reject-input-dialog',
+ children: {
+ title: validator.generateRuleErrorMessage(rule),
+ },
+ footer: {
+ title: React.createElement(
+ Button,
+ {
+ type: 'primary',
+ onClick: () => this._dialogService.close('reject-input-dialog'),
+ },
+ this._localeService.t('dataValidation.alert.ok')
+ ),
+ },
+ onClose: () => {
+ this._dialogService.close('reject-input-dialog');
+ },
+ });
+ return next(Promise.resolve(oldCell));
+ },
+ }
+ );
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
new file mode 100644
index 0000000000..8e59bf0916
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
@@ -0,0 +1,324 @@
+/**
+ * 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 type { ICellDataForSheetInterceptor, ICellRenderContext } from '@univerjs/core';
+import { DataValidationStatus, DataValidationType, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, WrapStrategy } from '@univerjs/core';
+import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
+import { ComponentManager, IMenuService } from '@univerjs/ui';
+import { Inject, Injector } from '@wendellhu/redi';
+import { IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
+import type { Spreadsheet } from '@univerjs/engine-render';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';
+import { DataValidationRenderMode } from '@univerjs/core/types/enum/data-validation-render-mode.js';
+import { DataValidationPanel, DATE_DROPDOWN_KEY, DateDropdown, LIST_DROPDOWN_KEY, ListDropDown } from '../views';
+import { FORMULA_INPUTS } from '../views/formula-input';
+import { getCellValueOrigin } from '../utils/get-cell-data-origin';
+import type { CheckboxValidator, ListValidator } from '../validators';
+import type { SheetDataValidationManager } from '../models/sheet-data-validation-manager';
+import { CellDropdown, DROP_DOWN_KEY } from '../views/drop-down';
+import { DataValidationDropdownManagerService } from '../services/dropdown-manager.service';
+import { ListRenderModeInput } from '../views/render-mode';
+import { DATA_VALIDATION_PANEL } from '../commands/operations/data-validation.operation';
+import { addDataValidationMenuFactory, dataValidationMenuFactory, openDataValidationMenuFactory } from './dv.menu';
+
+const INVALID_MARK = {
+ tr: {
+ size: 6,
+ color: '#fe4b4b',
+ },
+};
+
+@OnLifecycle(LifecycleStages.Rendered, DataValidationRenderController)
+export class DataValidationRenderController extends RxDisposable {
+ constructor(
+ @Inject(ComponentManager) private _componentManager: ComponentManager,
+ @IMenuService private _menuService: IMenuService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
+ @Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(DataValidatorRegistryService) private readonly _dataValidatorRegistryService: DataValidatorRegistryService,
+ @IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,
+ @Inject(DataValidationDropdownManagerService) private readonly _dropdownManagerService: DataValidationDropdownManagerService,
+ @Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,
+ @Inject(Injector) private readonly _injector: Injector
+ ) {
+ super();
+ this._init();
+ }
+
+ private _init() {
+ this._initComponents();
+ this._initMenu();
+ this._initSkeletonChange();
+ this._initDropdown();
+ this._initViewModelIntercept();
+ }
+
+ private _initMenu() {
+ [
+ dataValidationMenuFactory,
+ openDataValidationMenuFactory,
+ addDataValidationMenuFactory,
+ ].forEach((menu) => {
+ this.disposeWithMe(
+ this._menuService.addMenuItem(
+ menu(this._injector)
+ )
+ );
+ });
+ }
+
+ private _initComponents() {
+ ([
+ [
+ DATA_VALIDATION_PANEL,
+ DataValidationPanel,
+ ],
+ [
+ DROP_DOWN_KEY,
+ CellDropdown,
+ ],
+ [
+ LIST_DROPDOWN_KEY,
+ ListDropDown,
+ ],
+ [
+ DATE_DROPDOWN_KEY,
+ DateDropdown,
+ ],
+ [
+ ListRenderModeInput.componentKey,
+ ListRenderModeInput,
+ ],
+ ...FORMULA_INPUTS,
+ ] as const).forEach(([key, component]) => {
+ this.disposeWithMe(this._componentManager.register(
+ key,
+ component
+ ));
+ });
+ }
+
+ private _initDropdown() {
+ this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
+ if (!visible.visible) {
+ return;
+ }
+
+ const state = this._editorBridgeService.getEditCellState();
+ if (state) {
+ const { unitId, sheetId, row, column } = state;
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
+ if (!workbook) {
+ return;
+ }
+ const manager = this._dataValidationModel.ensureManager(unitId, sheetId) as SheetDataValidationManager;
+ const rule = manager.getRuleByLocation(row, column);
+
+ if (!rule) {
+ return;
+ }
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
+
+ if (!validator?.dropdown) {
+ return;
+ }
+
+ const worksheet = workbook.getActiveSheet();
+ const activeDropdown = this._dropdownManagerService.activeDropdown;
+ const currLoc = activeDropdown?.location;
+ if (
+ currLoc &&
+ currLoc.unitId === unitId &&
+ currLoc.subUnitId === sheetId &&
+ currLoc.row === row &&
+ currLoc.col === column
+ ) {
+ return;
+ }
+
+ this._dropdownManagerService.showDropdown({
+ location: {
+ unitId,
+ subUnitId: sheetId,
+ row,
+ col: column,
+ workbook,
+ worksheet,
+ },
+ componentKey: validator.dropdown,
+ onHide: () => { },
+ });
+ }
+ }));
+ }
+
+ private _initSkeletonChange() {
+ const markSkeletonDirty = () => {
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ const unitId = workbook.getUnitId();
+ const subUnitId = workbook.getActiveSheet().getSheetId();
+ const skeleton = this._sheetSkeletonManagerService.getOrCreateSkeleton({ unitId, sheetId: subUnitId });
+ const currentRender = this._renderManagerService.getRenderById(unitId);
+
+ skeleton?.makeDirty(true);
+ skeleton?.calculate();
+
+ if (currentRender) {
+ (currentRender.mainComponent as Spreadsheet).makeForceDirty();
+ }
+ };
+
+ this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(() => {
+ markSkeletonDirty();
+ }));
+
+ this.disposeWithMe(this._dataValidationModel.validStatusChange$.subscribe(() => {
+ markSkeletonDirty();
+ }));
+ }
+
+ private _initViewModelIntercept() {
+ this.disposeWithMe(
+ this._sheetInterceptorService.intercept(
+ INTERCEPTOR_POINT.CELL_CONTENT,
+ {
+ handler: (cell, pos, next) => {
+ const { row, col, unitId, subUnitId } = pos;
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+ const skeleton = this._sheetSkeletonManagerService.getCurrent()?.skeleton;
+ if (!manager || !skeleton) {
+ return next(cell);
+ }
+ const styleMap = pos.workbook.getStyles();
+ const defaultStyle = (typeof cell?.s === 'string' ? styleMap.get(cell?.s) : cell?.s) || {};
+ const ruleId = manager.getRuleIdByLocation(row, col);
+ if (!ruleId) {
+ return next(cell);
+ }
+ const rule = manager.getRuleById(ruleId);
+
+ if (!rule) {
+ return next(cell);
+ }
+ const cellRaw = pos.worksheet.getCellRaw(pos.row, pos.col);
+ const validStatus = this._dataValidationModel.validator(getCellValueOrigin(cellRaw), rule, pos);
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
+ const cellValue = getCellValueOrigin(cell);
+
+ 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) {
+ const { formula2 } = (validator as CheckboxValidator).parseFormulaSync(rule, pos.unitId, pos.subUnitId);
+ if (!cellValue) {
+ extra = {
+ v: formula2,
+ t: 1,
+ p: null,
+ 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(cell) ?? ''}`;
+ const color = colorMap[valueStr];
+ if (color) {
+ extra = {
+ ...extra,
+ interceptorStyle: {
+ ...extra.interceptorStyle,
+ bg: {
+ rgb: color,
+ },
+ },
+ };
+ }
+ }
+
+ return next({
+ ...cell,
+ ...extra,
+ dataValidation: {
+ ruleId,
+ validStatus,
+ rule,
+ validator,
+ },
+ markers: {
+ ...cell?.markers,
+ ...validStatus === DataValidationStatus.INVALID ? INVALID_MARK : null,
+ },
+ customRender: [
+ ...(cell?.customRender ?? []),
+ ...(validator?.canvasRender ? [validator.canvasRender] : []),
+ ],
+ // @ts-ignore
+ fontRenderExtension: {
+ // @ts-ignore
+ ...cell?.fontRenderExtension,
+ isSkip: validator?.skipDefaultFontRender(rule, cellValue, pos),
+ },
+ interceptorStyle: {
+ ...cell?.interceptorStyle,
+ ...extra.interceptorStyle,
+ },
+ get interceptorAutoHeight() {
+ const mergeCell = skeleton.mergeData.find((range) => {
+ const { startColumn, startRow, endColumn, endRow } = range;
+ return row >= startRow && col >= startColumn && row <= endRow && col <= endColumn;
+ });
+
+ const info: ICellRenderContext = {
+ data: {
+ ...cell,
+ dataValidation: {
+ ruleId,
+ validStatus,
+ rule,
+ validator,
+ },
+ },
+ style: skeleton.getsStyles().getStyleByCell(cell),
+ primaryWithCoord: skeleton.getCellByIndex(mergeCell?.startRow ?? row, mergeCell?.startColumn ?? col),
+ unitId,
+ subUnitId,
+ row,
+ col,
+ };
+ return validator?.canvasRender?.calcCellAutoHeight?.(info);
+ },
+ });
+ },
+ }
+ )
+ );
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv-resource.controller.ts b/packages/sheets-data-validation/src/controllers/dv-resource.controller.ts
new file mode 100644
index 0000000000..aa3cd1df7d
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-resource.controller.ts
@@ -0,0 +1,103 @@
+/**
+ * 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 type { ISheetDataValidationRule, Workbook } from '@univerjs/core';
+import { Disposable, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';
+import { DataValidationModel } from '@univerjs/data-validation';
+import { Inject, Injector } from '@wendellhu/redi';
+import { DATA_VALIDATION_PLUGIN_NAME } from '../common/const';
+import { SheetDataValidationManager } from '../models/sheet-data-validation-manager';
+
+type DataValidationJSON = Record<string, ISheetDataValidationRule[]>;
+
+@OnLifecycle(LifecycleStages.Ready, DataValidationResourceController)
+export class DataValidationResourceController extends Disposable {
+ constructor(
+ @IResourceManagerService private readonly _resourceManagerService: IResourceManagerService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
+ @Inject(Injector) private readonly _injector: Injector
+ ) {
+ super();
+ this._initDataValidationDataSource();
+ this._initSnapshot();
+ }
+
+ private _createSheetDataValidationManager(unitId: string, subUnitId: string) {
+ return new SheetDataValidationManager(
+ unitId,
+ subUnitId,
+ [],
+ this._injector
+ );
+ }
+
+ private _initDataValidationDataSource() {
+ this._dataValidationModel.setManagerCreator(this._createSheetDataValidationManager.bind(this));
+ }
+
+ private _initSnapshot() {
+ const toJson = (unitID: string) => {
+ const map = this._dataValidationModel.getUnitRules(unitID);
+ const resultMap: DataValidationJSON = {};
+ if (map) {
+ map.forEach(([key, v]) => {
+ resultMap[key] = v;
+ });
+ return JSON.stringify(resultMap);
+ }
+ return '';
+ };
+ const parseJson = (json: string): DataValidationJSON => {
+ if (!json) {
+ return {};
+ }
+ try {
+ return JSON.parse(json);
+ } catch (err) {
+ return {};
+ }
+ };
+ const handleWorkbookAdd = (workbook: Workbook) => {
+ const unitID = workbook.getUnitId();
+ this.disposeWithMe(
+ this._resourceManagerService.registerPluginResource<DataValidationJSON>(unitID, DATA_VALIDATION_PLUGIN_NAME, {
+ toJson: (unitID) => toJson(unitID),
+ parseJson: (json) => parseJson(json),
+ onChange: (unitID, value) => {
+ Object.keys(value).forEach((subunitId) => {
+ const ruleList = value[subunitId];
+ ruleList.forEach((rule) => {
+ this._dataValidationModel.addRule(unitID, subunitId, rule);
+ });
+ });
+ },
+ })
+ );
+ };
+ this.disposeWithMe(toDisposable(this._univerInstanceService.sheetAdded$.subscribe(handleWorkbookAdd)));
+ this.disposeWithMe(
+ toDisposable(
+ this._univerInstanceService.sheetDisposed$.subscribe((workbook) => {
+ const unitID = workbook.getUnitId();
+ this._resourceManagerService.disposePluginResource(unitID, DATA_VALIDATION_PLUGIN_NAME);
+ })
+ )
+ );
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ handleWorkbookAdd(workbook);
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv-sheet.controller.ts b/packages/sheets-data-validation/src/controllers/dv-sheet.controller.ts
new file mode 100644
index 0000000000..2b8628778a
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv-sheet.controller.ts
@@ -0,0 +1,82 @@
+/**
+ * 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 { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import type { IAddDataValidationMutationParams, IRemoveDataValidationMutationParams } from '@univerjs/data-validation';
+import { AddDataValidationMutation, DataValidationModel, RemoveDataValidationMutation } from '@univerjs/data-validation';
+import type { IRemoveSheetCommandParams } from '@univerjs/sheets';
+import { RemoveSheetCommand, SheetInterceptorService } from '@univerjs/sheets';
+import { Inject, Injector } from '@wendellhu/redi';
+
+@OnLifecycle(LifecycleStages.Ready, DataValidationSheetController)
+export class DataValidationSheetController extends Disposable {
+ constructor(
+ @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,
+ @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
+ @Inject(Injector) private _injector: Injector
+ ) {
+ super();
+ this._initSheetChange();
+ }
+
+ private _initSheetChange() {
+ this.disposeWithMe(
+ this._sheetInterceptorService.interceptCommand({
+ getMutations: (commandInfo) => {
+ if (commandInfo.id === RemoveSheetCommand.id) {
+ const params = commandInfo.params as IRemoveSheetCommandParams;
+ const unitId = params.unitId || this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
+ if (!workbook) {
+ return { redos: [], undos: [] };
+ }
+ const subUnitId = params.subUnitId || workbook.getActiveSheet().getSheetId();
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
+ if (!manager) {
+ return { redos: [], undos: [] };
+ }
+
+ const rules = manager.getDataValidations();
+ const ids = rules.map((i) => i.uid);
+ const redoParams: IRemoveDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ ruleId: ids,
+ };
+ const undoParams: IAddDataValidationMutationParams = {
+ unitId,
+ subUnitId,
+ rule: rules,
+ };
+
+ return {
+ redos: [{
+ id: RemoveDataValidationMutation.id,
+ params: redoParams,
+ }],
+ undos: [{
+ id: AddDataValidationMutation.id,
+ params: undoParams,
+ }],
+ };
+ }
+ return { redos: [], undos: [] };
+ },
+ })
+ );
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv.controller.ts b/packages/sheets-data-validation/src/controllers/dv.controller.ts
new file mode 100644
index 0000000000..ccb64b1bea
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv.controller.ts
@@ -0,0 +1,123 @@
+/**
+ * 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 { IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';
+import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
+import { Inject, Injector } from '@wendellhu/redi';
+import { DataValidationSingle } from '@univerjs/icons';
+import { ComponentManager } from '@univerjs/ui';
+import { ClearSelectionAllCommand, SelectionManagerService, SheetInterceptorService } from '@univerjs/sheets';
+import { SheetDataValidationService } from '../services/dv.service';
+import { CustomFormulaValidator } from '../validators/custom-validator';
+import { CheckboxValidator, DateValidator, DecimalValidator, ListValidator, TextLengthValidator } from '../validators';
+import { WholeValidator } from '../validators/whole-validator';
+import { ListMultipleValidator } from '../validators/list-multiple-validator';
+import type { SheetDataValidationManager } from '../models/sheet-data-validation-manager';
+import { getDataValidationDiffMutations } from '../commands/commands/data-validation.command';
+import { DataValidationIcon } from './dv.menu';
+
+@OnLifecycle(LifecycleStages.Rendered, DataValidationController)
+export class DataValidationController extends RxDisposable {
+ constructor(
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(SheetDataValidationService) private readonly _sheetDataValidationService: SheetDataValidationService,
+ @Inject(DataValidatorRegistryService) private readonly _dataValidatorRegistryService: DataValidatorRegistryService,
+ @Inject(Injector) private readonly _injector: Injector,
+ @Inject(ComponentManager) private readonly _componentManger: ComponentManager,
+ @Inject(SelectionManagerService) private _selectionManagerService: SelectionManagerService,
+ @Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel
+ ) {
+ super();
+ this._init();
+ }
+
+ private _init() {
+ this._registerValidators();
+ this._initInstanceChange();
+ this._componentManger.register(DataValidationIcon, DataValidationSingle);
+ this._initCommandInterceptor();
+ }
+
+ private _registerValidators() {
+ ([
+ DecimalValidator,
+ WholeValidator,
+ TextLengthValidator,
+ DateValidator,
+ CheckboxValidator,
+ ListValidator,
+ ListMultipleValidator,
+ CustomFormulaValidator,
+ ]).forEach((Validator) => {
+ const validator = this._injector.createInstance(Validator as typeof ListValidator);
+ this.disposeWithMe(
+ this._dataValidatorRegistryService.register(validator)
+ );
+ this.disposeWithMe({
+ dispose: () => {
+ this._injector.delete(Validator as typeof ListValidator);
+ },
+ });
+ });
+ }
+
+ private _initInstanceChange() {
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ this._sheetDataValidationService.switchCurrent(workbook.getUnitId(), workbook.getActiveSheet().getSheetId());
+ this.disposeWithMe(
+ workbook.activeSheet$.subscribe((worksheet) => {
+ if (worksheet) {
+ const unitId = workbook.getUnitId();
+ const subUnitId = worksheet.getSheetId();
+ this._sheetDataValidationService.switchCurrent(unitId, subUnitId);
+ }
+ })
+ );
+ }
+
+ private _initCommandInterceptor() {
+ this._sheetInterceptorService.interceptCommand({
+ getMutations: (commandInfo) => {
+ if (commandInfo.id === ClearSelectionAllCommand.id) {
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ const unitId = workbook.getUnitId();
+ const worksheet = workbook.getActiveSheet();
+ const subUnitId = worksheet.getSheetId();
+ const selections = this._selectionManagerService.getSelectionRanges();
+
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+
+ const ruleMatrix = manager.getRuleObjectMatrix().clone();
+
+ selections && ruleMatrix.removeRange(selections);
+ const diffs = ruleMatrix.diff(manager.getDataValidations());
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs);
+
+ return {
+ undos: undoMutations,
+ redos: redoMutations,
+ };
+ }
+
+ return {
+ undos: [],
+ redos: [],
+ };
+ },
+ });
+ }
+}
diff --git a/packages/sheets-data-validation/src/controllers/dv.menu.ts b/packages/sheets-data-validation/src/controllers/dv.menu.ts
new file mode 100644
index 0000000000..aa77bfaac4
--- /dev/null
+++ b/packages/sheets-data-validation/src/controllers/dv.menu.ts
@@ -0,0 +1,54 @@
+/**
+ * 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 { getMenuHiddenObservable, type IMenuItem, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
+import type { IAccessor } from '@wendellhu/redi';
+import { UniverInstanceType } from '@univerjs/core';
+import { AddSheetDataValidationAndOpenCommand } from '../commands/commands/data-validation.command';
+import { OpenValidationPanelOperation } from '../commands/operations/data-validation.operation';
+
+export const DataValidationIcon = 'data-validation-single';
+const DATA_VALIDATION_MENU_ID = 'sheet.menu.data-validation';
+
+export function dataValidationMenuFactory(accessor: IAccessor): IMenuItem {
+ return {
+ id: DATA_VALIDATION_MENU_ID,
+ type: MenuItemType.SUBITEMS,
+ positions: [MenuPosition.TOOLBAR_START],
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
+ icon: DataValidationIcon,
+ tooltip: 'dataValidation.title',
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
+ };
+}
+
+export function openDataValidationMenuFactory(_accessor: IAccessor): IMenuItem {
+ return {
+ id: OpenValidationPanelOperation.id,
+ title: 'dataValidation.panel.title',
+ type: MenuItemType.BUTTON,
+ positions: [DATA_VALIDATION_MENU_ID],
+ };
+}
+
+export function addDataValidationMenuFactory(_accessor: IAccessor): IMenuItem {
+ return {
+ id: AddSheetDataValidationAndOpenCommand.id,
+ title: 'dataValidation.panel.add',
+ type: MenuItemType.BUTTON,
+ positions: [DATA_VALIDATION_MENU_ID],
+ };
+}
diff --git a/packages/sheets-data-validation/src/index.ts b/packages/sheets-data-validation/src/index.ts
new file mode 100644
index 0000000000..ccba96575d
--- /dev/null
+++ b/packages/sheets-data-validation/src/index.ts
@@ -0,0 +1,37 @@
+/**
+ * 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.
+ */
+
+export { UniverSheetsDataValidationPlugin } from './plugin';
+export type { IAddSheetDataValidationCommandParams, IUpdateSheetDataValidationRangeCommandParams } from './commands/commands/data-validation.command';
+export { ICommandService, LocaleService, Plugin } from '@univerjs/core';
+export { DataValidationRenderController } from './controllers/dv-render.controller';
+export { DataValidationController } from './controllers/dv.controller';
+export { SheetDataValidationService } from './services/dv.service';
+export { DataValidationAlertController } from './controllers/dv-alert.controller';
+export { AddSheetDataValidationAndOpenCommand, AddSheetDataValidationCommand, UpdateSheetDataValidationRangeCommand } from './commands/commands/data-validation.command';
+export { DataValidationCacheService } from './services/dv-cache.service';
+export { DataValidationFormulaService } from './services/dv-formula.service';
+export { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';
+export { RegisterOtherFormulaService } from './services/register-formula.service';
+export { DataValidationRefRangeController } from './controllers/dv-ref-range.controller';
+export { DataValidationFormulaMarkDirty } from './commands/mutations/formula.mutation';
+export { DATA_VALIDATION_PLUGIN_NAME } from './common/const';
+export { DataValidationAutoFillController } from './controllers/dv-auto-fill.controller';
+export { DataValidationSheetController } from './controllers/dv-sheet.controller';
+export { DataValidationCopyPasteController } from './controllers/dv-copy-paste.controller';
+export { DataValidationResourceController } from './controllers/dv-resource.controller';
+export { HideDataValidationDropdown, ShowDataValidationDropdown } from './commands/operations/data-validation.operation';
+export { DataValidationRejectInputController } from './controllers/dv-reject-input.controller';
diff --git a/packages/sheets-data-validation/src/locales/enUS.ts b/packages/sheets-data-validation/src/locales/enUS.ts
new file mode 100644
index 0000000000..220b047660
--- /dev/null
+++ b/packages/sheets-data-validation/src/locales/enUS.ts
@@ -0,0 +1,156 @@
+/**
+ * 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.
+ */
+
+export default {
+ dataValidation: {
+ title: 'Data validation',
+ validFail: {
+ common: 'Please input value or formula',
+ number: 'Please input number or formula',
+ formula: 'Please input formula',
+ integer: 'Please input integer or formula',
+ date: 'Please input date or formula',
+ list: 'Please input options',
+ },
+ panel: {
+ title: 'Data validation management',
+ addTitle: 'Create new data validation',
+ removeAll: 'Remove All',
+ add: 'Create Data validation',
+ range: 'Ranges',
+ type: 'Type',
+ options: 'Advance options',
+ operator: 'Operator',
+ removeRule: 'Remove',
+ done: 'Done',
+ formulaPlaceholder: 'Please input value or formula',
+ formulaAnd: 'and',
+ invalid: 'Invalid',
+ showWarning: 'Show warning',
+ rejectInput: 'Reject input',
+ messageInfo: 'Helper message',
+ showInfo: 'Show help text for a selected cell',
+ validFailMessage: 'Please input value or formula',
+ },
+ operators: {
+ between: 'between',
+ greaterThan: 'greater than',
+ greaterThanOrEqual: 'greater than or equal',
+ lessThan: 'less than',
+ lessThanOrEqual: 'less than or equal',
+ equal: 'equal',
+ notEqual: 'not equal',
+ notBetween: 'not between',
+ },
+ ruleName: {
+ between: 'is between {FORMULA1} and {FORMULA2}',
+ greaterThan: 'is greater than {FORMULA1}',
+ greaterThanOrEqual: 'is greater than or equal to {FORMULA1}',
+ lessThan: 'is less than {FORMULA1}',
+ lessThanOrEqual: 'is less than or equal to {FORMULA1}',
+ equal: 'is equal to {FORMULA1}',
+ notEqual: 'is not equal to {FORMULA1}',
+ notBetween: 'is not between {FORMULA1} and {FORMULA2}',
+ },
+ errorMsg: {
+ between: 'Value must be between {FORMULA1} and {FORMULA2}',
+ greaterThan: 'Value must be greater than {FORMULA1}',
+ greaterThanOrEqual: 'Value must be greater than or equal to {FORMULA1}',
+ lessThan: 'Value must be less than {FORMULA1}',
+ lessThanOrEqual: 'Value must be less than or equal to {FORMULA1}',
+ equal: 'Value must be equal to {FORMULA1}',
+ notEqual: 'Value must be not equal to {FORMULA1}',
+ notBetween: 'Value must be not between {FORMULA1} and {FORMULA2}',
+ },
+ date: {
+ title: 'Date',
+ operators: {
+ between: 'between',
+ greaterThan: 'after',
+ greaterThanOrEqual: 'on or after',
+ lessThan: 'before',
+ lessThanOrEqual: 'on or before',
+ equal: 'equal',
+ notEqual: 'not equal',
+ notBetween: 'not between',
+ },
+ ruleName: {
+ between: 'is between {FORMULA1} and {FORMULA2}',
+ greaterThan: 'is after {FORMULA1}',
+ greaterThanOrEqual: 'is on or after {FORMULA1}',
+ lessThan: 'is before {FORMULA1}',
+ lessThanOrEqual: 'is on or before {FORMULA1}',
+ equal: 'is {FORMULA1}',
+ notEqual: 'is not {FORMULA1}',
+ notBetween: 'is not between {FORMULA1}',
+ },
+ errorMsg: {
+ between: 'Value must be between {FORMULA1} and {FORMULA2}',
+ greaterThan: 'Value must be after {FORMULA1}',
+ greaterThanOrEqual: 'Value must be on or after {FORMULA1}',
+ lessThan: 'Value must be before {FORMULA1}',
+ lessThanOrEqual: 'Value must be on or before {FORMULA1}',
+ equal: 'Value must be {FORMULA1}',
+ notEqual: 'Value must be not {FORMULA1}',
+ notBetween: 'Value must be not between {FORMULA1}',
+ },
+ },
+ list: {
+ title: 'Dropdown',
+ name: 'Value contains one from range',
+ error: 'Input must fall within specified range',
+ emptyError: 'Please enter a value',
+ add: 'Add',
+ dropdown: 'Select',
+ },
+ listMultiple: {
+ title: 'Dropdown-Multiple',
+ dropdown: 'Multiple select',
+ },
+ textLength: {
+ title: 'Text length',
+ },
+ number: {
+ title: 'Number',
+ },
+ decimal: {
+ title: 'Decimal',
+ },
+ checkbox: {
+ title: 'Checkbox',
+ error: 'This cell\'s contents violate its validation rule',
+ tips: '在单元格内使用自定义值',
+ },
+ custom: {
+ title: 'Custom formula',
+ error: 'This cell\'s contents violate its validation rule',
+ validFail: 'Please input a valid formula',
+ },
+ alert: {
+ title: 'Error',
+ ok: 'OK',
+ },
+ error: {
+ title: 'Invalid:',
+ },
+ renderMode: {
+ arrow: 'Arrow',
+ chip: 'Chip',
+ text: 'Plain text',
+ label: 'Display style',
+ },
+ },
+};
diff --git a/packages/sheets-data-validation/src/locales/index.ts b/packages/sheets-data-validation/src/locales/index.ts
new file mode 100644
index 0000000000..d47f3914e6
--- /dev/null
+++ b/packages/sheets-data-validation/src/locales/index.ts
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */
+
+export { default as enUS } from './enUS';
+export { default as zhCN } from './zhCN';
diff --git a/packages/sheets-data-validation/src/locales/zhCN.ts b/packages/sheets-data-validation/src/locales/zhCN.ts
new file mode 100644
index 0000000000..067dfa9856
--- /dev/null
+++ b/packages/sheets-data-validation/src/locales/zhCN.ts
@@ -0,0 +1,158 @@
+/**
+ * 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.
+ */
+
+export default {
+ dataValidation: {
+ title: '数据验证',
+ validFail: {
+ common: '请输入值或公式',
+ number: '请输入合法的数字或公式',
+ formula: '请输入合法的公式或公式',
+ integer: '请输入合法的整数或公式',
+ date: '请输入合法的日期或公式',
+ list: '请输入至少一个合法选项',
+ },
+ panel: {
+ title: '管理数据验证',
+ addTitle: '新建数据验证',
+ removeAll: '全部删除',
+ add: '新建规则',
+ range: '应用范围',
+ type: '条件类型',
+ options: '高级设置',
+ operator: '数据',
+ removeRule: '删除规则',
+ done: '确认',
+ formulaPlaceholder: '请输入值或公式',
+ formulaAnd: '与',
+ invalid: '数据无效时',
+ showWarning: '显示警告',
+ rejectInput: '拒绝输入',
+ messageInfo: '文字提示',
+ showInfo: '显示所选单元格的提示文字',
+ },
+ operators: {
+ between: '介于',
+ greaterThan: '大于',
+ greaterThanOrEqual: '大于或等于',
+ lessThan: '小于',
+ lessThanOrEqual: '小于或等于',
+ equal: '等于',
+ notEqual: '不等于',
+ notBetween: '未介于',
+ },
+ ruleName: {
+ between: '介于 {FORMULA1} 和 {FORMULA2} 之间',
+ greaterThan: '大于 {FORMULA1}',
+ greaterThanOrEqual: '大于或等于 {FORMULA1}',
+ lessThan: '小于 {FORMULA1}',
+ lessThanOrEqual: '小于或等于 {FORMULA1}',
+ equal: '等于 {FORMULA1}',
+ notEqual: '不等于 {FORMULA1}',
+ notBetween: '在 {FORMULA1} 和 {FORMULA2} 范围之外',
+ },
+ errorMsg: {
+ between: '值必须介于 {FORMULA1} 和 {FORMULA2} 之间',
+ greaterThan: '值必须大于 {FORMULA1}',
+ greaterThanOrEqual: '值必须大于或等于 {FORMULA1}',
+ lessThan: '值必须小于 {FORMULA1}',
+ lessThanOrEqual: '值必须小于或等于 {FORMULA1}',
+ equal: '值必须等于 {FORMULA1}',
+ notEqual: '值必须不等于 {FORMULA1}',
+ notBetween: '值必须在 {FORMULA1} 和 {FORMULA2} 范围之外',
+ },
+ date: {
+ title: '日期',
+ operators: {
+ between: '介于',
+ greaterThan: '大于',
+ greaterThanOrEqual: '大于或等于',
+ lessThan: '小于',
+ lessThanOrEqual: '小于或等于',
+ equal: '等于',
+ notEqual: '不等于',
+ notBetween: '未介于',
+ },
+ ruleName: {
+ between: '介于 {FORMULA1} 和 {FORMULA2} 之间',
+ greaterThan: '晚于 {FORMULA1}',
+ greaterThanOrEqual: '晚于或等于 {FORMULA1}',
+ lessThan: '早于 {FORMULA1}',
+ lessThanOrEqual: '早于或等于 {FORMULA1}',
+ equal: '等于 {FORMULA1}',
+ notEqual: '不等于 {FORMULA1}',
+ notBetween: '在 {FORMULA1} 和 {FORMULA2} 范围之外',
+ },
+ errorMsg: {
+ between: '日期必须介于 {FORMULA1} 和 {FORMULA2} 之间',
+ greaterThan: '日期必须晚于 {FORMULA1}',
+ greaterThanOrEqual: '日期必须晚于或等于 {FORMULA1}',
+ lessThan: '日期必须早于 {FORMULA1}',
+ lessThanOrEqual: '早于或等于 {FORMULA1}',
+ equal: '日期必须等于 {FORMULA1}',
+ notEqual: '日期必须不等于 {FORMULA1}',
+ notBetween: '日期必须在 {FORMULA1} 和 {FORMULA2} 范围之外',
+ },
+ },
+ list: {
+ title: '下拉菜单',
+ name: '值必须是列表中的值',
+ error: '输入必须在指定的范围内',
+ emptyError: '请输入一个值',
+ strPlaceholder: '请输入选项,选项间通过“回车换行”或“英文逗号(,)”隔开',
+ refPlaceholder: '引用单元格内容作为选项,如:\'Sheet1\'!A100',
+ add: '添加选项',
+ dropdown: '单选',
+ },
+ listMultiple: {
+ title: '下拉菜单-多选',
+ dropdown: '多选',
+ },
+ textLength: {
+ title: '文本长度',
+ },
+ decimal: {
+ title: '小数',
+ },
+ whole: {
+ title: '整数',
+ },
+ checkbox: {
+ title: '复选框',
+ error: '此单元格的内容违反了验证规则',
+ tips: '在单元格内使用自定义值',
+ checked: '选中值',
+ unchecked: '未选中值',
+ },
+ custom: {
+ title: '自定义公式',
+ error: '此单元格的内容违反了验证规则',
+ },
+ alert: {
+ title: '提示',
+ ok: '确定',
+ },
+ error: {
+ title: '无效:',
+ },
+ renderMode: {
+ arrow: '箭头',
+ chip: '条状标签',
+ text: '纯文本',
+ label: '显示样式',
+ },
+ },
+};
diff --git a/packages/sheets-data-validation/src/models/rule-matrix.ts b/packages/sheets-data-validation/src/models/rule-matrix.ts
new file mode 100644
index 0000000000..dfb82b5158
--- /dev/null
+++ b/packages/sheets-data-validation/src/models/rule-matrix.ts
@@ -0,0 +1,172 @@
+/**
+ * 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 { type IRange, type ISheetDataValidationRule, ObjectMatrix, Range, Rectangle } from '@univerjs/core';
+import { queryObjectMatrix } from '@univerjs/core';
+
+export type RangeMutation = {
+ type: 'update';
+ ruleId: string;
+ oldRanges: IRange[];
+ newRanges: IRange[];
+} | {
+ type: 'delete';
+ rule: ISheetDataValidationRule;
+ index: number;
+} | {
+ type: 'add';
+ rule: ISheetDataValidationRule;
+};
+
+export class RuleMatrix {
+ readonly value: ObjectMatrix<string>;
+
+ constructor(value: ObjectMatrix<string>) {
+ this.value = value;
+ }
+
+ addRule(rule: ISheetDataValidationRule) {
+ const ruleId = rule.uid;
+ rule.ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ this.value.setValue(row, col, ruleId);
+ });
+ });
+ }
+
+ removeRange(ranges: IRange[]) {
+ ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ this.value.realDeleteValue(row, col);
+ });
+ });
+ }
+
+ removeRule(rule: ISheetDataValidationRule) {
+ rule.ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ this.value.setValue(row, col, '');
+ });
+ });
+ }
+
+ updateRange(ruleId: string, oldRanges: IRange[], newRanges: IRange[]) {
+ const tempRuleId = `${ruleId}$`;
+ oldRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ if (this.value.getValue(row, col) === ruleId) {
+ this.value.setValue(row, col, tempRuleId);
+ }
+ });
+ });
+
+ newRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ this.value.setValue(row, col, ruleId);
+ });
+ });
+
+ oldRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const value = this.value.getValue(row, col);
+ if (value === tempRuleId) {
+ this.value.realDeleteValue(row, col);
+ }
+ });
+ });
+ }
+
+ diff(rules: ISheetDataValidationRule[]) {
+ const mutations: RangeMutation[] = [];
+ let deleteIndex = 0;
+ rules.forEach((rule, index) => {
+ const newRanges = queryObjectMatrix(this.value, (ruleId) => ruleId === rule.uid);
+ const oldRanges = rule.ranges;
+
+ if (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) {
+ mutations.push({
+ type: 'update',
+ ruleId: rule.uid,
+ oldRanges,
+ newRanges,
+ });
+ }
+
+ if (newRanges.length === 0) {
+ mutations.push({
+ type: 'delete',
+ rule,
+ index: index - deleteIndex,
+ });
+ deleteIndex++;
+ }
+ });
+
+ return mutations;
+ }
+
+ diffWithAddition(rules: ISheetDataValidationRule[], additionRules: IterableIterator<ISheetDataValidationRule>) {
+ const mutations: RangeMutation[] = [];
+ let deleteIndex = 0;
+ rules.forEach((rule, index) => {
+ const newRanges = queryObjectMatrix(this.value, (ruleId) => ruleId === rule.uid);
+ const oldRanges = rule.ranges;
+
+ if (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) {
+ mutations.push({
+ type: 'update',
+ ruleId: rule.uid,
+ oldRanges,
+ newRanges,
+ });
+ }
+
+ if (newRanges.length === 0) {
+ mutations.push({
+ type: 'delete',
+ rule,
+ index: index - deleteIndex,
+ });
+ deleteIndex++;
+ }
+ });
+
+ Array.from(additionRules).forEach((rule) => {
+ const newRanges = queryObjectMatrix(this.value, (ruleId) => ruleId === rule.uid);
+ mutations.push({
+ type: 'add',
+ rule: {
+ ...rule,
+ ranges: newRanges,
+ },
+ });
+ });
+
+ return mutations;
+ }
+
+ clone() {
+ return new RuleMatrix(new ObjectMatrix(this.value.clone()));
+ }
+
+ getValue(row: number, col: number) {
+ return this.value.getValue(row, col);
+ }
+
+ setValue(row: number, col: number, value: string) {
+ return this.value.setValue(row, col, value);
+ }
+}
diff --git a/packages/sheets-data-validation/src/models/sheet-data-validation-manager.ts b/packages/sheets-data-validation/src/models/sheet-data-validation-manager.ts
new file mode 100644
index 0000000000..7190d0f5b4
--- /dev/null
+++ b/packages/sheets-data-validation/src/models/sheet-data-validation-manager.ts
@@ -0,0 +1,176 @@
+/**
+ * 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 type { CellValue } from '@univerjs/core/types/interfaces/index.js';
+import { DataValidationManager } from '@univerjs/data-validation/models/data-validation-manager.js';
+import type { Nullable } from '@univerjs/core/shared/index.js';
+import { ObjectMatrix } from '@univerjs/core/shared/index.js';
+import { Range } from '@univerjs/core/sheets/range.js';
+import type { IUpdateRulePayload } from '@univerjs/data-validation/types/interfaces/i-update-rule-payload.js';
+import { DataValidatorRegistryService, UpdateRuleType } from '@univerjs/data-validation';
+import type { ISheetDataValidationRule } from '@univerjs/core';
+import { DataValidationStatus } from '@univerjs/core';
+import type { ISheetLocation } from '@univerjs/sheets';
+import type { Injector } from '@wendellhu/redi';
+import type { IDataValidationResCache } from '../services/dv-cache.service';
+import { DataValidationCacheService } from '../services/dv-cache.service';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';
+import { DataValidationRefRangeController } from '../controllers/dv-ref-range.controller';
+import { RuleMatrix } from './rule-matrix';
+
+export class SheetDataValidationManager extends DataValidationManager<ISheetDataValidationRule> {
+ /**
+ * save cell's ruleId
+ */
+ private _ruleMatrix: RuleMatrix;
+ private _dataValidatorRegistryService: DataValidatorRegistryService;
+ private _dataValidationCacheService: DataValidationCacheService;
+ private _dataValidationFormulaService: DataValidationFormulaService;
+ private _dataValidationCustomFormulaService: DataValidationCustomFormulaService;
+ private _cache: ObjectMatrix<Nullable<IDataValidationResCache>>;
+ private _dataValidationRefRangeController: DataValidationRefRangeController;
+
+ constructor(
+ unitId: string,
+ subUnitId: string,
+ rules: ISheetDataValidationRule[] | undefined,
+ private readonly _injector: Injector
+ ) {
+ super(unitId, subUnitId, rules);
+ this._dataValidatorRegistryService = this._injector.get(DataValidatorRegistryService);
+ this._dataValidationCacheService = this._injector.get(DataValidationCacheService);
+ this._dataValidationFormulaService = this._injector.get(DataValidationFormulaService);
+ this._dataValidationCustomFormulaService = this._injector.get(DataValidationCustomFormulaService);
+ this._dataValidationRefRangeController = this._injector.get(DataValidationRefRangeController);
+ this._cache = this._dataValidationCacheService.ensureCache(unitId, subUnitId);
+
+ const matrix = new ObjectMatrix<string>();
+ rules?.forEach((rule) => {
+ const ruleId = rule.uid;
+ rule.ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ matrix.setValue(row, col, ruleId);
+ });
+ });
+ });
+
+ rules?.forEach((rule) => {
+ this._dataValidationRefRangeController.register(unitId, subUnitId, rule);
+ });
+ this._ruleMatrix = new RuleMatrix(matrix);
+ }
+
+ override addRule(rule: ISheetDataValidationRule): void {
+ this._ruleMatrix.addRule(rule);
+ this._dataValidationCacheService.addRule(this.unitId, this.subUnitId, rule);
+ this._dataValidationFormulaService.addRule(this.unitId, this.subUnitId, rule.uid, rule.formula1, rule.formula2);
+ this._dataValidationCustomFormulaService.addRule(this.unitId, this.subUnitId, rule);
+ super.addRule(rule);
+ }
+
+ override updateRule(ruleId: string, payload: IUpdateRulePayload) {
+ const oldRule = this.getRuleById(ruleId);
+
+ if (!oldRule) {
+ throw new Error(`Rule not found! id: ${ruleId}`);
+ }
+
+ if (payload.type === UpdateRuleType.RANGE) {
+ this._ruleMatrix.updateRange(ruleId, oldRule.ranges, payload.payload);
+ this._dataValidationCacheService.updateRuleRanges(this.unitId, this.subUnitId, ruleId, payload.payload, oldRule.ranges);
+ this._dataValidationCustomFormulaService.updateRuleRanges(this.unitId, this.subUnitId, ruleId, oldRule.ranges, payload.payload);
+ } else if (payload.type === UpdateRuleType.SETTING) {
+ this._dataValidationCacheService.markRangeDirty(this.unitId, this.subUnitId, oldRule.ranges);
+ this._dataValidationFormulaService.updateRuleFormulaText(this.unitId, this.subUnitId, ruleId, payload.payload.formula1, payload.payload.formula2);
+ this._dataValidationCustomFormulaService.updateRuleFormula(this.unitId, this.subUnitId, ruleId, oldRule.ranges, payload.payload.formula1!);
+ }
+
+ return super.updateRule(ruleId, payload);
+ }
+
+ override removeRule(ruleId: string): void {
+ const oldRule = this.getRuleById(ruleId);
+ if (oldRule) {
+ this._ruleMatrix.removeRule(oldRule);
+ this._dataValidationCacheService.removeRule(this.unitId, this.subUnitId, oldRule);
+ }
+ super.removeRule(ruleId);
+ }
+
+ getRuleIdByLocation(row: number, col: number): string | undefined {
+ return this._ruleMatrix.getValue(row, col);
+ }
+
+ getRuleByLocation(row: number, col: number): ISheetDataValidationRule | undefined {
+ const ruleId = this.getRuleIdByLocation(row, col);
+ if (!ruleId) {
+ return undefined;
+ }
+
+ return this.getRuleById(ruleId);
+ }
+
+ override validator(cellValue: Nullable<CellValue>, rule: ISheetDataValidationRule, pos: ISheetLocation, onCompete: (status: DataValidationStatus) => void): DataValidationStatus {
+ const { col, row, unitId, subUnitId } = pos;
+ const ruleId = rule.uid;
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
+ if (validator) {
+ const current = this._cache.getValue(row, col);
+ if (!current || current.value !== cellValue) {
+ this._cache.setValue(row, col, {
+ value: cellValue,
+ status: DataValidationStatus.VALIDATING,
+ ruleId,
+ });
+ validator.validator({ value: cellValue, unitId, subUnitId, row, column: col }, rule).then((status) => {
+ const realStatus = status ? DataValidationStatus.VALID : DataValidationStatus.INVALID;
+ this._cache.setValue(row, col, {
+ value: cellValue,
+ status: realStatus,
+ ruleId,
+ });
+ onCompete(realStatus);
+ });
+ return DataValidationStatus.VALIDATING;
+ }
+ return current.status;
+ } else {
+ return DataValidationStatus.VALID;
+ }
+ }
+
+ getRuleErrorMsg(ruleId: string) {
+ const rule = this.getRuleById(ruleId);
+ if (!rule) {
+ return '';
+ }
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
+ if (rule.error) {
+ return rule.error;
+ }
+
+ if (validator) {
+ return validator.getRuleFinalError(rule);
+ }
+
+ return '';
+ }
+
+ getRuleObjectMatrix() {
+ return this._ruleMatrix;
+ }
+}
diff --git a/packages/sheets-data-validation/src/plugin.ts b/packages/sheets-data-validation/src/plugin.ts
new file mode 100644
index 0000000000..67d74ff1ad
--- /dev/null
+++ b/packages/sheets-data-validation/src/plugin.ts
@@ -0,0 +1,95 @@
+/**
+ * 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 { ICommandService, LocaleService, Plugin } from '@univerjs/core';
+import { type Dependency, Inject, Injector } from '@wendellhu/redi';
+import { DataValidationRenderController } from './controllers/dv-render.controller';
+import { DataValidationController } from './controllers/dv.controller';
+import { SheetDataValidationService } from './services/dv.service';
+import { DataValidationAlertController } from './controllers/dv-alert.controller';
+import { AddSheetDataValidationAndOpenCommand, AddSheetDataValidationCommand, UpdateSheetDataValidationRangeCommand } from './commands/commands/data-validation.command';
+import { DataValidationCacheService } from './services/dv-cache.service';
+import { DataValidationFormulaService } from './services/dv-formula.service';
+import { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';
+import { RegisterOtherFormulaService } from './services/register-formula.service';
+import { DataValidationRefRangeController } from './controllers/dv-ref-range.controller';
+import { DataValidationFormulaMarkDirty } from './commands/mutations/formula.mutation';
+import { enUS, zhCN } from './locales';
+import { DATA_VALIDATION_PLUGIN_NAME } from './common/const';
+import { DataValidationAutoFillController } from './controllers/dv-auto-fill.controller';
+import { DataValidationSheetController } from './controllers/dv-sheet.controller';
+import { DataValidationCopyPasteController } from './controllers/dv-copy-paste.controller';
+import { DataValidationResourceController } from './controllers/dv-resource.controller';
+import { DataValidationDropdownManagerService } from './services/dropdown-manager.service';
+import { CloseValidationPanelOperation, HideDataValidationDropdown, OpenValidationPanelOperation, ShowDataValidationDropdown, ToggleValidationPanelOperation } from './commands/operations/data-validation.operation';
+import { DataValidationRejectInputController } from './controllers/dv-reject-input.controller';
+import { DataValidationPanelService } from './services/data-validation-panel.service';
+
+export class UniverSheetsDataValidationPlugin extends Plugin {
+ constructor(
+ @Inject(Injector) protected _injector: Injector,
+ @ICommandService private readonly _commandService: ICommandService,
+ @Inject(LocaleService) private readonly _localeService: LocaleService
+ ) {
+ super(DATA_VALIDATION_PLUGIN_NAME);
+ }
+
+ override onStarting(injector: Injector) {
+ ([
+ [DataValidationPanelService],
+ [SheetDataValidationService],
+ [DataValidationCacheService],
+ [DataValidationFormulaService],
+ [DataValidationCustomFormulaService],
+ [RegisterOtherFormulaService],
+ [DataValidationDropdownManagerService],
+
+ // controller
+ [DataValidationResourceController],
+ [DataValidationController],
+ [DataValidationRenderController],
+ [DataValidationAlertController],
+ [DataValidationRefRangeController],
+ [DataValidationAutoFillController],
+ [DataValidationSheetController],
+ [DataValidationCopyPasteController],
+ [DataValidationRejectInputController],
+ ] as Dependency[]).forEach((dep) => {
+ injector.add(dep);
+ });
+
+ [
+ AddSheetDataValidationCommand,
+ AddSheetDataValidationAndOpenCommand,
+ UpdateSheetDataValidationRangeCommand,
+ DataValidationFormulaMarkDirty,
+
+ // operation
+ ShowDataValidationDropdown,
+ HideDataValidationDropdown,
+ CloseValidationPanelOperation,
+ OpenValidationPanelOperation,
+ ToggleValidationPanelOperation,
+ ].forEach((command) => {
+ this._commandService.registerCommand(command);
+ });
+
+ this._localeService.load({
+ zhCN,
+ enUS,
+ });
+ }
+}
diff --git a/packages/sheets-data-validation/src/services/data-validation-panel.service.ts b/packages/sheets-data-validation/src/services/data-validation-panel.service.ts
new file mode 100644
index 0000000000..6e1b8cdd5b
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/data-validation-panel.service.ts
@@ -0,0 +1,54 @@
+/**
+ * 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 type { IDataValidationRule, Nullable } from '@univerjs/core';
+import { Disposable } from '@univerjs/core';
+import { BehaviorSubject, distinctUntilChanged } from 'rxjs';
+
+export class DataValidationPanelService extends Disposable {
+ private _open$ = new BehaviorSubject<boolean>(false);
+ private _activeRule: Nullable<{ unitId: string; subUnitId: string; rule: IDataValidationRule }> = undefined;
+ private _activeRule$ = new BehaviorSubject<Nullable<{ unitId: string; subUnitId: string; rule: IDataValidationRule }>>(undefined);
+
+ open$ = this._open$.pipe(distinctUntilChanged());
+ activeRule$ = this._activeRule$.asObservable();
+
+ get activeRule() {
+ return this._activeRule;
+ }
+
+ get isOpen(): boolean {
+ return this._open$.getValue();
+ }
+
+ override dispose(): void {
+ this._open$.next(false);
+ this._open$.complete();
+ }
+
+ open(): void {
+ this._open$.next(true);
+ }
+
+ close(): void {
+ this._open$.next(false);
+ }
+
+ setActiveRule(rule: Nullable<{ unitId: string; subUnitId: string; rule: IDataValidationRule }>): void {
+ this._activeRule = rule;
+ this._activeRule$.next(rule);
+ }
+}
diff --git a/packages/sheets-data-validation/src/services/dropdown-manager.service.ts b/packages/sheets-data-validation/src/services/dropdown-manager.service.ts
new file mode 100644
index 0000000000..6be64875e4
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/dropdown-manager.service.ts
@@ -0,0 +1,163 @@
+/**
+ * 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 { Disposable, DisposableCollection, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, IUniverInstanceService, type Nullable } from '@univerjs/core';
+import type { ISheetLocation } from '@univerjs/sheets';
+import { Subject } from 'rxjs';
+import type { IDisposable } from '@wendellhu/redi';
+import { Inject } from '@wendellhu/redi';
+import { SheetCanvasPopManagerService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
+import { DataValidatorRegistryService } from '@univerjs/data-validation';
+import { IZenZoneService } from '@univerjs/ui';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import { DROP_DOWN_KEY } from '../views/drop-down';
+
+export interface IDropdownParam {
+ location: ISheetLocation;
+ onHide?: () => void;
+ componentKey: string;
+}
+
+export interface IDropdownComponentProps {
+ componentKey: string;
+ location: ISheetLocation;
+ hideFn: () => void;
+}
+
+export class DataValidationDropdownManagerService extends Disposable {
+ private _activeDropdown: Nullable<IDropdownParam>;
+ private _activeDropdown$ = new Subject<Nullable<IDropdownParam>>();
+ private _currentPopup: Nullable<IDisposable> = null;
+
+ activeDropdown$ = this._activeDropdown$.asObservable();
+
+ private _zenVisible = false;
+
+ get activeDropdown() {
+ return this._activeDropdown;
+ }
+
+ constructor(
+ @Inject(SheetCanvasPopManagerService) private readonly _canvasPopupManagerService: SheetCanvasPopManagerService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
+ @Inject(DataValidatorRegistryService) private readonly _dataValidatorRegistryService: DataValidatorRegistryService,
+ @IZenZoneService private readonly _zenZoneService: IZenZoneService,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService
+ ) {
+ super();
+ this._init();
+ }
+
+ private _init() {
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
+ this._zenVisible = visible;
+ if (visible) {
+ this.hideDropdown();
+ }
+ }));
+ }
+
+ showDropdown(param: IDropdownParam) {
+ const { location } = param;
+ const { row, col } = location;
+
+ this._currentPopup && this._currentPopup.dispose();
+
+ if (this._zenVisible) {
+ return;
+ }
+
+ this._activeDropdown = param;
+ this._activeDropdown$.next(this._activeDropdown);
+ const disposableCollection = new DisposableCollection();
+ const currentRender = this._renderManagerService.getRenderById(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
+ disposableCollection.add(this._canvasPopupManagerService.attachPopupToCell(
+ row,
+ col,
+ {
+ componentKey: DROP_DOWN_KEY,
+ onClickOutside: () => {
+ this.hideDropdown();
+ },
+ offset: [0, 3],
+ excludeOutside: [currentRender?.engine.getCanvasElement()].filter(Boolean) as HTMLElement[],
+ }
+ ));
+
+ disposableCollection.add({
+ dispose: () => {
+ this._activeDropdown?.onHide?.();
+ },
+ });
+
+ this._currentPopup = disposableCollection;
+ }
+
+ hideDropdown() {
+ if (!this._activeDropdown) {
+ return;
+ }
+ this._currentPopup && this._currentPopup.dispose();
+ this._currentPopup = null;
+
+ this._activeDropdown = null;
+ this._activeDropdown$.next(null);
+ }
+
+ showDataValidationDropdown(unitId: string, subUnitId: string, row: number, col: number, onHide?: () => void) {
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
+ if (!workbook) {
+ return;
+ }
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
+ if (!worksheet) {
+ return;
+ }
+
+ const cell = worksheet.getCell(row, col);
+ const rule = cell?.dataValidation?.rule;
+ const skeleton = this._sheetSkeletonManagerService.getOrCreateSkeleton({
+ unitId,
+ sheetId: subUnitId,
+ });
+
+ if (!skeleton) {
+ return;
+ }
+ if (!rule) {
+ return;
+ }
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
+ if (!validator || !validator.dropdown) {
+ this.hideDropdown();
+ return;
+ }
+
+ this.showDropdown({
+ location: {
+ workbook,
+ worksheet,
+ row,
+ col,
+ unitId,
+ subUnitId,
+ },
+ componentKey: validator.dropdown,
+ onHide,
+ });
+ }
+}
diff --git a/packages/sheets-data-validation/src/services/dv-cache.service.ts b/packages/sheets-data-validation/src/services/dv-cache.service.ts
new file mode 100644
index 0000000000..939440298f
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/dv-cache.service.ts
@@ -0,0 +1,122 @@
+/**
+ * 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 { ObjectMatrix, Range } from '@univerjs/core';
+import type { CellValue, DataValidationStatus, IRange, ISheetDataValidationRule, Nullable } from '@univerjs/core';
+
+export interface IDataValidationResCache {
+ value: Nullable<CellValue>;
+ status: DataValidationStatus;
+ ruleId: string;
+ temp?: boolean;
+}
+
+export class DataValidationCacheService {
+ private _cacheMatrix: Map<string, Map<string, ObjectMatrix<Nullable<IDataValidationResCache>>>> = new Map();
+
+ private _ensureCache(unitId: string, subUnitId: string) {
+ let unitMap = this._cacheMatrix.get(unitId);
+
+ if (!unitMap) {
+ unitMap = new Map();
+ this._cacheMatrix.set(unitId, unitMap);
+ }
+
+ let cacheMatrix = unitMap.get(subUnitId);
+
+ if (!cacheMatrix) {
+ cacheMatrix = new ObjectMatrix();
+ unitMap.set(subUnitId, cacheMatrix);
+ }
+
+ return cacheMatrix;
+ }
+
+ ensureCache(unitId: string, subUnitId: string) {
+ return this._ensureCache(unitId, subUnitId);
+ }
+
+ addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule) {
+ this.markRangeDirty(unitId, subUnitId, rule.ranges);
+ }
+
+ removeRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule) {
+ this._deleteRange(unitId, subUnitId, rule.ranges);
+ }
+
+ updateRuleRanges(unitId: string, subUnitId: string, ruleId: string, newRanges: IRange[], oldRanges: IRange[]) {
+ const cache = this._ensureCache(unitId, subUnitId);
+ oldRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const item = cache.getValue(row, col);
+ item && (item.temp = true);
+ });
+ });
+
+ newRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const item = cache.getValue(row, col);
+ if (item && item.ruleId === ruleId) {
+ item.temp = false;
+ } else {
+ cache.setValue(row, col, undefined);
+ }
+ });
+ });
+
+ oldRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const item = cache.getValue(row, col);
+ if (item && (item.temp === true)) {
+ cache.realDeleteValue(row, col);
+ }
+ });
+ });
+ }
+
+ markRangeDirty(unitId: string, subUnitId: string, ranges: IRange[]) {
+ const cache = this._ensureCache(unitId, subUnitId);
+ ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ cache.setValue(row, col, undefined);
+ });
+ });
+ }
+
+ markCellDirty(unitId: string, subUnitId: string, row: number, col: number) {
+ const cache = this._ensureCache(unitId, subUnitId);
+ cache.setValue(row, col, undefined);
+ }
+
+ private _deleteRange(unitId: string, subUnitId: string, ranges: IRange[]) {
+ const cache = this._ensureCache(unitId, subUnitId);
+ ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ cache.realDeleteValue(row, col);
+ });
+ });
+ }
+
+ getValue(unitId: string, subUnitId: string, row: number, col: number) {
+ const cache = this._ensureCache(unitId, subUnitId);
+ return cache.getValue(row, col);
+ }
+
+ setValue(unitId: string, subUnitId: string, row: number, col: number, value: IDataValidationResCache) {
+ const cache = this._ensureCache(unitId, subUnitId);
+ return cache.setValue(row, col, value);
+ }
+}
diff --git a/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts b/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts
new file mode 100644
index 0000000000..2d9f7bc39d
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts
@@ -0,0 +1,333 @@
+/**
+ * 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 type { IRange, ISheetDataValidationRule } from '@univerjs/core';
+import { DataValidationType, Disposable, isFormulaString, IUniverInstanceService, ObjectMatrix, Range } from '@univerjs/core';
+import { isFormulaTransformable, LexerTreeBuilder, transformFormula } from '@univerjs/engine-formula';
+import { Inject } from '@wendellhu/redi';
+import { DataValidationModel } from '@univerjs/data-validation';
+import { RegisterOtherFormulaService } from './register-formula.service';
+import { DataValidationCacheService } from './dv-cache.service';
+
+interface IDataValidationFormula {
+ ruleId: string;
+ // formulaText: string;
+ formulaId: string;
+ temp?: boolean;
+}
+
+interface IFormulaData {
+ formula: string;
+ originRow: number;
+ originCol: number;
+ isTransformable: boolean;
+ formulaId?: string;
+}
+
+interface ICellData {
+ row: number;
+ column: number;
+}
+
+type RuleId = string;
+type UnitId = string;
+type SubUnitId = string;
+type FormulaId = string;
+
+//
+export class DataValidationCustomFormulaService extends Disposable {
+ private _formulaMap: Map<UnitId, Map<SubUnitId, ObjectMatrix<IDataValidationFormula>>> = new Map();
+ /**
+ * Map of origin formula of rule
+ */
+ private _ruleFormulaMap: Map<UnitId, Map<SubUnitId, Map<RuleId, IFormulaData>>> = new Map();
+
+ /**
+ * reflect of formulaId to cell, only store transformable formula
+ */
+ private _formulaCellMap: Map<UnitId, Map<SubUnitId, Map<FormulaId, ICellData>>> = new Map();
+
+ constructor(
+ @Inject(RegisterOtherFormulaService) private _registerOtherFormulaService: RegisterOtherFormulaService,
+ @Inject(LexerTreeBuilder) private _lexerTreeBuilder: LexerTreeBuilder,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
+ @Inject(DataValidationCacheService) private readonly _dataValidationCacheService: DataValidationCacheService
+ ) {
+ super();
+
+ this._initFormulaResultHandler();
+ }
+
+ private _initFormulaResultHandler() {
+ this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
+ for (const unitId in resultMap) {
+ const unitMap = resultMap[unitId];
+ for (const subUnitId in unitMap) {
+ const results = unitMap[subUnitId];
+ const { formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
+ results.forEach((result) => {
+ const ruleInfo = ruleFormulaMap.get(result.ruleId);
+ const cellInfo = formulaCellMap.get(result.formulaId);
+ const rule = manager.getRuleById(result.ruleId);
+
+ if (rule && ruleInfo && !ruleInfo.isTransformable) {
+ this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
+ }
+
+ if (cellInfo) {
+ this._dataValidationCacheService.markCellDirty(unitId, subUnitId, cellInfo.row, cellInfo.column);
+ }
+ });
+ }
+ }
+ }));
+ }
+
+ private _ensureMaps(unitId: string, subUnitId: string) {
+ let formulaUnitMap = this._formulaMap.get(unitId);
+ let ruleFormulaUnitMap = this._ruleFormulaMap.get(unitId);
+ let formulaCellUnitMap = this._formulaCellMap.get(unitId);
+
+ if (!formulaUnitMap || !ruleFormulaUnitMap || !formulaCellUnitMap) {
+ formulaUnitMap = new Map<string, ObjectMatrix<IDataValidationFormula>>();
+ ruleFormulaUnitMap = new Map();
+ formulaCellUnitMap = new Map();
+ this._formulaMap.set(unitId, formulaUnitMap);
+ this._ruleFormulaMap.set(unitId, ruleFormulaUnitMap);
+ this._formulaCellMap.set(unitId, formulaCellUnitMap);
+ }
+
+ let formulaMap = formulaUnitMap.get(subUnitId);
+ let ruleFormulaMap = ruleFormulaUnitMap.get(subUnitId);
+ let formulaCellMap = formulaCellUnitMap.get(subUnitId);
+
+ if (!formulaMap || !ruleFormulaMap || !formulaCellMap) {
+ formulaMap = new ObjectMatrix<IDataValidationFormula>();
+ formulaUnitMap.set(subUnitId, formulaMap);
+
+ ruleFormulaMap = new Map();
+ ruleFormulaUnitMap.set(subUnitId, ruleFormulaMap);
+
+ formulaCellMap = new Map();
+ formulaCellUnitMap.set(subUnitId, formulaCellMap);
+
+ // if (rules) {
+ // rules.forEach((rule) => {
+ // if (rule.type === DataValidationType.CUSTOM) {
+ // this.addRule(unitId, subUnitId, rule);
+ // }
+ // });
+ // }
+ }
+ return {
+ formulaMap,
+ ruleFormulaMap,
+ formulaCellMap,
+ };
+ };
+
+ private _registerFormula(unitId: string, subUnitId: string, ruleId: string, formulaString: string) {
+ return this._registerOtherFormulaService.registerFormula(unitId, subUnitId, ruleId, formulaString);
+ };
+
+ deleteByRuleId(unitId: string, subUnitId: string, ruleId: string) {
+ const { formulaMap, formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
+ const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId) as ISheetDataValidationRule;
+ const formulaIdList = new Set<string>();
+ const formulaInfo = ruleFormulaMap.get(ruleId);
+
+ if (!rule || !formulaInfo) {
+ return;
+ }
+
+ // formulaIdList.add(formulaInfo.formulaId);
+ ruleFormulaMap.delete(ruleId);
+
+ rule.ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const value = formulaMap.getValue(row, col);
+ if (value && value.ruleId === ruleId) {
+ const { formulaId } = value;
+ formulaMap.realDeleteValue(row, col);
+ formulaIdList.add(formulaId);
+ formulaCellMap.delete(formulaId);
+ }
+ });
+ });
+
+ this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, Array.from(formulaIdList.values()));
+ }
+
+ private _addFormulaByRange(unitId: string, subUnitId: string, ruleId: string, formula: string, ranges: IRange[]) {
+ const { formulaMap, ruleFormulaMap, formulaCellMap } = this._ensureMaps(unitId, subUnitId);
+
+ if (!formula) {
+ return;
+ }
+
+ const isTransformable = isFormulaTransformable(
+ this._lexerTreeBuilder,
+ formula
+ );
+
+ const originRow = ranges[0].startRow;
+ const originCol = ranges[0].startColumn;
+
+ let originFormulaId: string | undefined;
+ if (isTransformable) {
+ ranges.forEach((range) => {
+ Range.foreach(range, (row, column) => {
+ const relativeFormula = transformFormula(
+ this._lexerTreeBuilder,
+ formula,
+ originRow,
+ originCol,
+ row,
+ column
+ );
+ const formulaId = this._registerFormula(unitId, subUnitId, ruleId, relativeFormula);
+ formulaMap.setValue(row, column, {
+ formulaId,
+ // formulaText: relativeFormula,
+ ruleId,
+ });
+ formulaCellMap.set(formulaId, { row, column });
+ });
+ });
+ } else {
+ originFormulaId = this._registerFormula(unitId, subUnitId, ruleId, formula);
+ ranges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ formulaMap.setValue(row, col, {
+ formulaId: originFormulaId!,
+ // formulaText: formula,
+ ruleId,
+ });
+ });
+ });
+ }
+
+ ruleFormulaMap.set(ruleId, {
+ formula,
+ originCol,
+ originRow,
+ isTransformable,
+ formulaId: originFormulaId,
+ });
+ }
+
+ addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule) {
+ const { ranges, formula1, uid: ruleId, type } = rule;
+ if (type !== DataValidationType.CUSTOM || !formula1 || !isFormulaString(formula1)) {
+ return;
+ }
+ this._addFormulaByRange(unitId, subUnitId, ruleId, formula1, ranges);
+ }
+
+ updateRuleRanges(unitId: string, subUnitId: string, ruleId: string, oldRanges: IRange[], newRanges: IRange[]) {
+ const { formulaMap, ruleFormulaMap, formulaCellMap } = this._ensureMaps(unitId, subUnitId);
+ const info = ruleFormulaMap.get(ruleId);
+ // isn't custom formula type
+ if (!info) {
+ return;
+ }
+ const { formula, originCol, originRow, isTransformable, formulaId } = info;
+ const deleteFormulaIdList = new Set<string>();
+
+ oldRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const value = formulaMap.getValue(row, col);
+ if (value && value.ruleId === ruleId) {
+ value.temp = true;
+ }
+ });
+ });
+
+ newRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const oldValue = formulaMap.getValue(row, col) ?? {};
+ if ((oldValue.ruleId !== ruleId)) {
+ const oldRuleFormula = ruleFormulaMap.get(oldValue.ruleId);
+ if (oldRuleFormula?.isTransformable) {
+ deleteFormulaIdList.add(oldValue.formulaId);
+ }
+
+ if (isTransformable) {
+ const relativeText = transformFormula(this._lexerTreeBuilder, formula, originRow, originCol, row, col);
+ const formulaId = this._registerFormula(unitId, subUnitId, ruleId, relativeText);
+ formulaMap.setValue(row, col, {
+ // formulaText: relativeText,
+ ruleId,
+ formulaId,
+ });
+ formulaCellMap.set(formulaId, { row, column: col });
+ } else {
+ formulaMap.setValue(row, col, {
+ // formulaText: formula,
+ ruleId,
+ formulaId: formulaId!,
+ });
+ }
+ } else {
+ oldValue.temp = false;
+ }
+ });
+ });
+
+ oldRanges.forEach((range) => {
+ Range.foreach(range, (row, col) => {
+ const value = formulaMap.getValue(row, col);
+ if (value && value.ruleId === ruleId && value.temp === true) {
+ formulaMap.realDeleteValue(row, col);
+ if (isTransformable) {
+ deleteFormulaIdList.add(value.formulaId);
+ }
+ }
+ });
+ });
+
+ deleteFormulaIdList.forEach((formulaId) => {
+ formulaCellMap.delete(formulaId);
+ });
+ this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, Array.from(deleteFormulaIdList.values()));
+ }
+
+ updateRuleFormula(unitId: string, subUnitId: string, ruleId: string, ranges: IRange[], formula: string) {
+ const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
+ const current = ruleFormulaMap.get(ruleId);
+ if (!current || current.formula !== formula) {
+ this._addFormulaByRange(unitId, subUnitId, ruleId, formula, ranges);
+ }
+ }
+
+ getCellFormulaValue(unitId: string, subUnitId: string, row: number, col: number) {
+ const { formulaMap } = this._ensureMaps(unitId, subUnitId);
+ const current = formulaMap.getValue(row, col);
+ if (!current) {
+ return Promise.resolve(undefined);
+ }
+
+ return this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId);
+ }
+
+ getRuleFormulaInfo(unitId: string, subUnitId: string, ruleId: string) {
+ const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
+
+ return ruleFormulaMap.get(ruleId);
+ }
+}
diff --git a/packages/sheets-data-validation/src/services/dv-formula.service.ts b/packages/sheets-data-validation/src/services/dv-formula.service.ts
new file mode 100644
index 0000000000..4596c155eb
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/dv-formula.service.ts
@@ -0,0 +1,194 @@
+/**
+ * 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 type { Nullable } from '@univerjs/core';
+import { Disposable, isFormulaString } from '@univerjs/core';
+import { Inject } from '@wendellhu/redi';
+import { DataValidationModel } from '@univerjs/data-validation';
+import type { IDataValidationFormulaResult, IFormulaInfo } from './formula-common';
+import { RegisterOtherFormulaService } from './register-formula.service';
+import { DataValidationCacheService } from './dv-cache.service';
+
+type RuleId = string;
+type UnitId = string;
+type SubUnitId = string;
+
+export class DataValidationFormulaService extends Disposable {
+ private _formulaRuleMap: Map<UnitId, Map<SubUnitId, Map<RuleId, [IFormulaInfo | undefined, IFormulaInfo | undefined]>>> = new Map();
+
+ constructor(
+ @Inject(RegisterOtherFormulaService) private _registerOtherFormulaService: RegisterOtherFormulaService,
+ // @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(DataValidationCacheService) private readonly _dataValidationCacheService: DataValidationCacheService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel
+ ) {
+ super();
+ this._initFormulaResultHandler();
+ }
+
+ private _initFormulaResultHandler() {
+ this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
+ for (const unitId in resultMap) {
+ const unitMap = resultMap[unitId];
+ for (const subUnitId in unitMap) {
+ const results = unitMap[subUnitId];
+ const formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
+ const manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
+ results.forEach((result) => {
+ if (formulaMap.get(result.ruleId)) {
+ const rule = manager.getRuleById(result.ruleId);
+ if (rule) {
+ this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
+ }
+ };
+ });
+ }
+ }
+ }));
+ }
+
+ private _ensureRuleFormulaMap(unitId: string, subUnitId: string) {
+ let unitMap = this._formulaRuleMap.get(unitId);
+
+ if (!unitMap) {
+ unitMap = new Map();
+ this._formulaRuleMap.set(unitId, unitMap);
+ }
+
+ let subUnitMap = unitMap.get(subUnitId);
+
+ if (!subUnitMap) {
+ subUnitMap = new Map();
+ unitMap.set(subUnitId, subUnitMap);
+ // const worksheet = this._univerInstanceService.getUniverSheetInstance(unitId)?.getSheetBySheetId(subUnitId);
+ // const rules = worksheet?.getSnapshot().dataValidation;
+ // if (rules) {
+ // rules.forEach((rule) => {
+ // if (rule.type !== DataValidationType.CUSTOM) {
+ // this.addRule(unitId, subUnitId, rule.uid, rule.formula1, rule.formula2);
+ // }
+ // });
+ // }
+ }
+
+ return subUnitMap;
+ }
+
+ addRule(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined) {
+ const isFormula1Legal = isFormulaString(formula1);
+ const isFormula2Legal = isFormulaString(formula2);
+ if (!isFormula1Legal && !isFormula2Legal) {
+ return;
+ }
+ const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId);
+ const item: [IFormulaInfo | undefined, IFormulaInfo | undefined] = [undefined, undefined];
+ if (isFormula1Legal) {
+ const id = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, ruleId, formula1!);
+
+ item[0] = { id, text: formula1! };
+ }
+ if (isFormula2Legal) {
+ const id = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, ruleId, formula2!);
+ item[1] = { id, text: formula2! };
+ }
+ formulaRuleMap.set(ruleId, item);
+ }
+
+ removeRule(unitId: string, subUnitId: string, ruleId: string) {
+ const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId);
+ const item = formulaRuleMap.get(ruleId);
+ if (!item) {
+ return;
+ }
+ const [formula1, formula2] = item;
+ const idList = [formula1?.id, formula2?.id].filter(Boolean) as string[];
+ idList.length && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, idList);
+ }
+
+ updateRuleFormulaText(unitId: string, subUnitId: string, ruleId: string, formula1: string | undefined, formula2: string | undefined) {
+ const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId);
+ const item = formulaRuleMap.get(ruleId);
+ if (!item) {
+ this.addRule(unitId, subUnitId, ruleId, formula1, formula2);
+ return;
+ }
+
+ const [oldFormula1, oldFormula2] = item;
+ if (oldFormula1?.text !== formula1) {
+ oldFormula1 && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [oldFormula1.id]);
+ if (isFormulaString(formula1)) {
+ const formulaId = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, ruleId, formula1!);
+ item[0] = {
+ text: formula1!,
+ id: formulaId,
+ };
+ } else {
+ item[0] = undefined;
+ };
+ }
+
+ if (oldFormula2?.text !== formula2) {
+ oldFormula2 && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [oldFormula2.id]);
+ if (isFormulaString(formula2)) {
+ const formulaId = this._registerOtherFormulaService.registerFormula(unitId, subUnitId, ruleId, formula2!);
+ item[1] = {
+ text: formula2!,
+ id: formulaId,
+ };
+ } else {
+ item[1] = undefined;
+ };
+ }
+ }
+
+ getRuleFormulaResult(unitId: string, subUnitId: string, ruleId: string): Promise<Nullable<[Nullable<IDataValidationFormulaResult>, Nullable<IDataValidationFormulaResult>]>> {
+ const ruleFormulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
+
+ const formulaInfo = ruleFormulaMap.get(ruleId);
+ if (!formulaInfo) {
+ return Promise.resolve(null);
+ }
+ const getResult = async (info: IFormulaInfo | undefined) => info && this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, info.id);
+
+ return Promise.all([
+ getResult(formulaInfo[0]),
+ getResult(formulaInfo[1]),
+ ]);
+ }
+
+ getRuleFormulaResultSync(unitId: string, subUnitId: string, ruleId: string) {
+ const ruleFormulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
+
+ const formulaInfo = ruleFormulaMap.get(ruleId);
+
+ if (!formulaInfo) {
+ return undefined;
+ }
+
+ return formulaInfo.map((i) => {
+ if (i) {
+ return this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, i.id);
+ }
+
+ return undefined;
+ });
+ }
+
+ getRuleFormulaInfo(unitId: string, subUnitId: string, ruleId: string) {
+ const ruleFormulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
+ return ruleFormulaMap.get(ruleId);
+ }
+}
diff --git a/packages/sheets-data-validation/src/services/dv.service.ts b/packages/sheets-data-validation/src/services/dv.service.ts
new file mode 100644
index 0000000000..47bae410df
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/dv.service.ts
@@ -0,0 +1,65 @@
+/**
+ * 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 type { Nullable } from '@univerjs/core';
+import { Subject } from 'rxjs';
+import { DataValidationModel } from '@univerjs/data-validation';
+import { Inject } from '@wendellhu/redi';
+import type { SheetDataValidationManager } from '../models/sheet-data-validation-manager';
+
+export interface ICurrentDataValidationManager {
+ manager: SheetDataValidationManager;
+ unitId: string;
+ subUnitId: string;
+}
+
+export class SheetDataValidationService {
+ private _currentManager: Nullable<ICurrentDataValidationManager>;
+
+ private _currentManager$ = new Subject<ICurrentDataValidationManager>();
+
+ get currentManager() {
+ return this._currentManager;
+ }
+
+ currentManager$ = this._currentManager$.asObservable();
+
+ constructor(
+ @Inject(DataValidationModel) private _dataValidationModel: DataValidationModel
+ ) { }
+
+ private _ensureManager(unitId: string, subUnitId: string) {
+ return this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+ }
+
+ switchCurrent(unitId: string, subUnitId: string) {
+ if (unitId === this.currentManager?.unitId && subUnitId === this._currentManager?.subUnitId) {
+ return;
+ }
+
+ const manager = this._ensureManager(unitId, subUnitId);
+ this._currentManager = {
+ manager,
+ unitId,
+ subUnitId,
+ };
+ this._currentManager$.next(this._currentManager);
+ }
+
+ get(unitId: string, subUnitId: string) {
+ return this._ensureManager(unitId, subUnitId);
+ }
+}
diff --git a/packages/sheets-data-validation/src/services/dv.tips.ts b/packages/sheets-data-validation/src/services/dv.tips.ts
new file mode 100644
index 0000000000..0b3f71d1e7
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/dv.tips.ts
@@ -0,0 +1,19 @@
+/**
+ * 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.
+ */
+
+export class SheetDataValidationTipsService {
+
+}
diff --git a/packages/sheets-data-validation/src/services/formula-common.ts b/packages/sheets-data-validation/src/services/formula-common.ts
new file mode 100644
index 0000000000..c5729c0c38
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/formula-common.ts
@@ -0,0 +1,37 @@
+/**
+ * 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 type { ICellData, Nullable } from '@univerjs/core';
+
+export enum FormulaResultStatus {
+ NOT_REGISTER = 1,
+ SUCCESS,
+ WAIT,
+ ERROR,
+}
+
+export interface IDataValidationFormulaResult {
+ result?: Nullable<ICellData>[][];
+ status: FormulaResultStatus;
+ ruleId: string;
+ formulaId: string;
+ callbacks: Set<(value: Nullable<ICellData>[][]) => void>;
+}
+
+export interface IFormulaInfo {
+ id: string;
+ text: string;
+}
diff --git a/packages/sheets-data-validation/src/services/register-formula.service.ts b/packages/sheets-data-validation/src/services/register-formula.service.ts
new file mode 100644
index 0000000000..a20616c124
--- /dev/null
+++ b/packages/sheets-data-validation/src/services/register-formula.service.ts
@@ -0,0 +1,193 @@
+/**
+ * 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 type { Nullable } from '@univerjs/core';
+import { Disposable, ICommandService, Tools } from '@univerjs/core';
+import type { IRemoveOtherFormulaMutationParams, ISetFormulaCalculationResultMutation, ISetOtherFormulaMutationParams } from '@univerjs/engine-formula';
+import { IActiveDirtyManagerService, RemoveOtherFormulaMutation, SetFormulaCalculationResultMutation, SetOtherFormulaMutation } from '@univerjs/engine-formula';
+import { bufferTime, filter, map, Subject } from 'rxjs';
+import type { IDataValidationFormulaMarkDirtyParams } from '../commands/mutations/formula.mutation';
+import { DataValidationFormulaMarkDirty } from '../commands/mutations/formula.mutation';
+import { FormulaResultStatus, type IDataValidationFormulaResult } from './formula-common';
+
+export class RegisterOtherFormulaService extends Disposable {
+ private _formulaCacheMap: Map<string, Map<string, Map<string, IDataValidationFormulaResult>>> = new Map();
+
+ private _formulaChange$ = new Subject<{ unitId: string; subUnitId: string; ruleId: string; formulaText: string; formulaId: string }>();
+ public formulaChange$ = this._formulaChange$.asObservable();
+
+ private _formulaResult$ = new Subject<Record<string, Record<string, IDataValidationFormulaResult[]>>>();
+ public formulaResult$ = this._formulaResult$.asObservable();
+
+ constructor(
+ @ICommandService private readonly _commandService: ICommandService,
+ @IActiveDirtyManagerService private _activeDirtyManagerService: IActiveDirtyManagerService
+ ) {
+ super();
+ this._initFormulaRegister();
+ this._initFormulaCalculationResultChange();
+ }
+
+ private _ensureCacheMap(unitId: string, subUnitId: string) {
+ let unitMap = this._formulaCacheMap.get(unitId);
+
+ if (!unitMap) {
+ unitMap = new Map();
+ this._formulaCacheMap.set(unitId, unitMap);
+ }
+
+ let subUnitMap = unitMap.get(subUnitId);
+
+ if (!subUnitMap) {
+ subUnitMap = new Map();
+ unitMap.set(subUnitId, subUnitMap);
+ }
+
+ return subUnitMap;
+ }
+
+ private _createFormulaId(unitId: string, subUnitId: string) {
+ return `sheet.dv_${unitId}_${subUnitId}_${Tools.generateRandomId(8)}`;
+ }
+
+ private _initFormulaRegister() {
+ this._activeDirtyManagerService.register(DataValidationFormulaMarkDirty.id,
+ { commandId: DataValidationFormulaMarkDirty.id,
+ getDirtyData(commandInfo) {
+ const params = commandInfo.params as IDataValidationFormulaMarkDirtyParams;
+ return {
+ dirtyUnitOtherFormulaMap: params,
+ };
+ } });
+
+ this.formulaChange$.pipe(bufferTime(16), filter((list) => !!list.length), map((list) => {
+ return list.reduce((result, cur) => {
+ const { unitId, subUnitId, formulaId, formulaText } = cur;
+ if (!result[unitId]) {
+ result[unitId] = {};
+ }
+ if (!result[unitId][subUnitId]) {
+ result[unitId][subUnitId] = {};
+ }
+ result[unitId][subUnitId][formulaId] = { f: formulaText };
+ return result;
+ }, {} as { [unitId: string]: { [sunUnitId: string]: { [formulaId: string]: { f: string } } } });
+ })).subscribe((result) => {
+ for (const unitId in result) {
+ for (const subUnitId in result[unitId]) {
+ const value = result[unitId][subUnitId];
+ const config: ISetOtherFormulaMutationParams = { unitId, subUnitId, formulaMap: value };
+ this._commandService.executeCommand(SetOtherFormulaMutation.id, config).then(() => {
+ this._commandService.executeCommand(DataValidationFormulaMarkDirty.id,
+ { [unitId]: { [subUnitId]: value } } as unknown as IDataValidationFormulaMarkDirtyParams);
+ });
+ }
+ }
+ });
+ }
+
+ private _initFormulaCalculationResultChange() {
+ // Gets the result of the formula calculation and caches it
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
+ if (commandInfo.id === SetFormulaCalculationResultMutation.id) {
+ const params = commandInfo.params as ISetFormulaCalculationResultMutation;
+
+ const { unitOtherData } = params;
+ const results: Record<string, Record<string, IDataValidationFormulaResult[]>> = {};
+ for (const unitId in unitOtherData) {
+ const unitData = unitOtherData[unitId];
+ const unitResults: Record<string, IDataValidationFormulaResult[]> = {};
+ results[unitId] = unitResults;
+ for (const subUnitId in unitData) {
+ const cacheMap = this._ensureCacheMap(unitId, subUnitId);
+ const subUnitData = unitData[subUnitId];
+ const subUnitResults: IDataValidationFormulaResult[] = [];
+ unitResults[subUnitId] = subUnitResults;
+ for (const formulaId in subUnitData) {
+ const current = subUnitData[formulaId];
+ if (cacheMap.has(formulaId)) {
+ const item = cacheMap.get(formulaId)!;
+ item.result = current;
+ item.status = FormulaResultStatus.SUCCESS;
+ item.callbacks.forEach((callback) => {
+ callback(current);
+ });
+ item.callbacks.clear();
+ subUnitResults.push(item);
+ }
+ }
+ }
+ }
+ this._formulaResult$.next(results);
+ }
+ }));
+ }
+
+ registerFormula(unitId: string, subUnitId: string, ruleId: string, formulaText: string) {
+ const formulaId = this._createFormulaId(unitId, subUnitId);
+ const cacheMap = this._ensureCacheMap(unitId, subUnitId);
+
+ cacheMap.set(formulaId, {
+ result: undefined,
+ status: FormulaResultStatus.WAIT,
+ ruleId,
+ formulaId,
+ callbacks: new Set(),
+ });
+ this._formulaChange$.next({
+ unitId,
+ ruleId,
+ subUnitId,
+ formulaText,
+ formulaId,
+ });
+ return formulaId;
+ }
+
+ deleteFormula(unitId: string, subUnitId: string, formulaIdList: string[]) {
+ const params: IRemoveOtherFormulaMutationParams = {
+ unitId,
+ subUnitId,
+ formulaIdList,
+ };
+ this._commandService.executeCommand(RemoveOtherFormulaMutation.id, params);
+ const cacheMap = this._ensureCacheMap(unitId, subUnitId);
+ formulaIdList.forEach((id) => cacheMap.delete(id));
+ }
+
+ getFormulaValue(unitId: string, subUnitId: string, formulaId: string): Promise<Nullable<IDataValidationFormulaResult>> {
+ const cacheMap = this._ensureCacheMap(unitId, subUnitId);
+ const item = cacheMap.get(formulaId);
+ if (!item) {
+ return Promise.resolve(null);
+ }
+
+ if (item.status === FormulaResultStatus.SUCCESS || FormulaResultStatus.ERROR) {
+ return Promise.resolve(item);
+ }
+
+ return new Promise((resolve) => {
+ item.callbacks.add(() => {
+ resolve(cacheMap.get(formulaId));
+ });
+ });
+ }
+
+ getFormulaValueSync(unitId: string, subUnitId: string, formulaId: string): Nullable<IDataValidationFormulaResult> {
+ const cacheMap = this._ensureCacheMap(unitId, subUnitId);
+ return cacheMap.get(formulaId);
+ }
+}
diff --git a/packages/sheets-data-validation/src/types/const/index.ts b/packages/sheets-data-validation/src/types/const/index.ts
new file mode 100644
index 0000000000..cb69cde545
--- /dev/null
+++ b/packages/sheets-data-validation/src/types/const/index.ts
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */
+
+export * from './operator-text-map';
+export * from './two-formula-operators';
diff --git a/packages/sheets-data-validation/src/types/const/operator-text-map.ts b/packages/sheets-data-validation/src/types/const/operator-text-map.ts
new file mode 100644
index 0000000000..82622a5c48
--- /dev/null
+++ b/packages/sheets-data-validation/src/types/const/operator-text-map.ts
@@ -0,0 +1,50 @@
+/**
+ * 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 { DataValidationOperator } from '@univerjs/core';
+
+export const OperatorTextMap: Record<DataValidationOperator, string> = {
+ [DataValidationOperator.BETWEEN]: 'dataValidation.operators.between',
+ [DataValidationOperator.EQUAL]: 'dataValidation.operators.equal',
+ [DataValidationOperator.GREATER_THAN]: 'dataValidation.operators.greaterThan',
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: 'dataValidation.operators.greaterThanOrEqual',
+ [DataValidationOperator.LESS_THAN]: 'dataValidation.operators.lessThan',
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: 'dataValidation.operators.lessThanOrEqual',
+ [DataValidationOperator.NOT_BETWEEN]: 'dataValidation.operators.notBetween',
+ [DataValidationOperator.NOT_EQUAL]: 'dataValidation.operators.notEqual',
+};
+
+export const OperatorTitleMap: Record<DataValidationOperator, string> = {
+ [DataValidationOperator.BETWEEN]: 'dataValidation.ruleName.between',
+ [DataValidationOperator.EQUAL]: 'dataValidation.ruleName.equal',
+ [DataValidationOperator.GREATER_THAN]: 'dataValidation.ruleName.greaterThan',
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: 'dataValidation.ruleName.greaterThanOrEqual',
+ [DataValidationOperator.LESS_THAN]: 'dataValidation.ruleName.lessThan',
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: 'dataValidation.ruleName.lessThanOrEqual',
+ [DataValidationOperator.NOT_BETWEEN]: 'dataValidation.ruleName.notBetween',
+ [DataValidationOperator.NOT_EQUAL]: 'dataValidation.ruleName.notEqual',
+};
+
+export const OperatorErrorTitleMap: Record<DataValidationOperator, string> = {
+ [DataValidationOperator.BETWEEN]: 'dataValidation.errorMsg.between',
+ [DataValidationOperator.EQUAL]: 'dataValidation.errorMsg.equal',
+ [DataValidationOperator.GREATER_THAN]: 'dataValidation.errorMsg.greaterThan',
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: 'dataValidation.errorMsg.greaterThanOrEqual',
+ [DataValidationOperator.LESS_THAN]: 'dataValidation.errorMsg.lessThan',
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: 'dataValidation.errorMsg.lessThanOrEqual',
+ [DataValidationOperator.NOT_BETWEEN]: 'dataValidation.errorMsg.notBetween',
+ [DataValidationOperator.NOT_EQUAL]: 'dataValidation.errorMsg.notEqual',
+};
diff --git a/packages/sheets-data-validation/src/types/const/two-formula-operators.ts b/packages/sheets-data-validation/src/types/const/two-formula-operators.ts
new file mode 100644
index 0000000000..5c263a039d
--- /dev/null
+++ b/packages/sheets-data-validation/src/types/const/two-formula-operators.ts
@@ -0,0 +1,22 @@
+/**
+ * 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 { DataValidationOperator } from '@univerjs/core';
+
+export const TWO_FORMULA_OPERATOR_COUNT: DataValidationOperator[] = [
+ DataValidationOperator.BETWEEN,
+ DataValidationOperator.NOT_BETWEEN,
+];
diff --git a/packages/sheets-data-validation/src/types/index.ts b/packages/sheets-data-validation/src/types/index.ts
new file mode 100644
index 0000000000..0298a829cb
--- /dev/null
+++ b/packages/sheets-data-validation/src/types/index.ts
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */
+
+export * from './interface';
+export * from './const';
diff --git a/packages/sheets-data-validation/src/types/interface/i-update-rule-formula.ts b/packages/sheets-data-validation/src/types/interface/i-update-rule-formula.ts
new file mode 100644
index 0000000000..b703d83d26
--- /dev/null
+++ b/packages/sheets-data-validation/src/types/interface/i-update-rule-formula.ts
@@ -0,0 +1,20 @@
+/**
+ * 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.
+ */
+
+export interface IUpdateDataValidationFormulaPayload {
+ type: 'formula1' | 'formula2';
+ formulaString: string;
+}
diff --git a/packages/sheets-data-validation/src/types/interface/index.ts b/packages/sheets-data-validation/src/types/interface/index.ts
new file mode 100644
index 0000000000..8130232e90
--- /dev/null
+++ b/packages/sheets-data-validation/src/types/interface/index.ts
@@ -0,0 +1,17 @@
+/**
+ * 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.
+ */
+
+export * from './i-update-rule-formula';
diff --git a/packages/sheets-data-validation/src/utils/date.ts b/packages/sheets-data-validation/src/utils/date.ts
new file mode 100644
index 0000000000..0df4a076d1
--- /dev/null
+++ b/packages/sheets-data-validation/src/utils/date.ts
@@ -0,0 +1,67 @@
+/**
+ * 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.
+ */
+
+const DAY_SIZE = 86400;
+
+export function toYMD_1900(ord: number, leap1900 = true) {
+ if (leap1900 && ord >= 0) {
+ if (ord === 0) {
+ return [1900, 1, 0];
+ }
+ if (ord === 60) {
+ return [1900, 2, 29];
+ }
+ if (ord < 60) {
+ return [1900, (ord < 32 ? 1 : 2), ((ord - 1) % 31) + 1];
+ }
+ }
+ let l = ord + 68569 + 2415019;
+ const n = Math.floor((4 * l) / 146097);
+ l = l - Math.floor((146097 * n + 3) / 4);
+ const i = Math.floor((4000 * (l + 1)) / 1461001);
+ l = l - Math.floor((1461 * i) / 4) + 31;
+ const j = Math.floor((80 * l) / 2447);
+ const nDay = l - Math.floor((2447 * j) / 80);
+ l = Math.floor(j / 11);
+ const nMonth = j + 2 - (12 * l);
+ const nYear = 100 * (n - 49) + i + l;
+ return [nYear | 0, nMonth | 0, nDay | 0];
+}
+
+export const serialTimeToTimestamp = (value: number) => {
+ let date = (value | 0);
+ const t = DAY_SIZE * (value - date);
+ let time = Math.floor(t); // in seconds
+ // date "epsilon" correction
+ if ((t - time) > 0.9999) {
+ time += 1;
+ if (time === DAY_SIZE) {
+ time = 0;
+ date += 1;
+ }
+ }
+ // serial date/time to gregorian calendar
+ const x = (time < 0) ? DAY_SIZE + time : time;
+ const [y, m, d] = toYMD_1900(value, true);
+ const hh = Math.floor((x / 60) / 60) % 60;
+ const mm = Math.floor(x / 60) % 60;
+ const ss = Math.floor(x) % 60;
+ // return it as a native date object
+ const dt = new Date(0);
+ dt.setUTCFullYear(y, m - 1, d);
+ dt.setUTCHours(hh, mm, ss);
+ return dt.getTime();
+};
diff --git a/packages/sheets-data-validation/src/utils/formula.ts b/packages/sheets-data-validation/src/utils/formula.ts
new file mode 100644
index 0000000000..1e885b16a8
--- /dev/null
+++ b/packages/sheets-data-validation/src/utils/formula.ts
@@ -0,0 +1,21 @@
+/**
+ * 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 type { ICellData, Nullable } from '@univerjs/core';
+
+export function getFormulaResult(result: Nullable<Nullable<ICellData>[][]>) {
+ return result?.[0]?.[0]?.v;
+}
diff --git a/packages/sheets-data-validation/src/utils/get-cell-data-origin.ts b/packages/sheets-data-validation/src/utils/get-cell-data-origin.ts
new file mode 100644
index 0000000000..66b61bd76a
--- /dev/null
+++ b/packages/sheets-data-validation/src/utils/get-cell-data-origin.ts
@@ -0,0 +1,39 @@
+/**
+ * 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 { DEFAULT_EMPTY_DOCUMENT_VALUE, type ICellData, type Nullable } from '@univerjs/core';
+
+export function getCellValueOrigin(cell: Nullable<ICellData>) {
+ if (cell === null) {
+ return '';
+ }
+
+ if (cell?.p) {
+ const body = cell?.p.body;
+
+ if (body == null) {
+ return '';
+ }
+
+ const data = body.dataStream;
+ const lastString = data.substring(data.length - 2, data.length);
+ const newDataStream = lastString === DEFAULT_EMPTY_DOCUMENT_VALUE ? data.substring(0, data.length - 2) : data;
+
+ return newDataStream;
+ }
+
+ return cell?.v;
+}
diff --git a/packages/sheets-data-validation/src/validators/checkbox-validator.ts b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
new file mode 100644
index 0000000000..948b14a5fd
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
@@ -0,0 +1,91 @@
+/**
+ * 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 { DataValidationType, isFormulaString, Tools } from '@univerjs/core';
+import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase, ISheetDataValidationRule, Nullable } from '@univerjs/core';
+import { BaseDataValidator } from '@univerjs/data-validation';
+import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation/validators/base-data-validator.js';
+import type { ISheetLocation } from '@univerjs/sheets';
+import { CheckboxRender } from '../widgets/checkbox-widget';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+import { getFormulaResult } from '../utils/formula';
+import { CHECKBOX_FORMULA_INPUT_NAME } from '../views/formula-input';
+
+export const CHECKBOX_FORMULA_1 = 1;
+export const CHECKBOX_FORMULA_2 = 0;
+
+export class CheckboxValidator extends BaseDataValidator {
+ override id: string = DataValidationType.CHECKBOX;
+ override title: string = 'dataValidation.checkbox.title';
+ override operators: DataValidationOperator[] = [];
+ override scopes: string | string[] = ['sheet'];
+ override formulaInput: string = CHECKBOX_FORMULA_INPUT_NAME;
+
+ override canvasRender = this.injector.createInstance(CheckboxRender);
+
+ private _formulaService = this.injector.get(DataValidationFormulaService);
+
+ override skipDefaultFontRender(rule: ISheetDataValidationRule, cellValue: Nullable<CellValue>, pos: ISheetLocation) {
+ const { formula1, formula2 } = this.parseFormulaSync(rule, pos.unitId, pos.subUnitId);
+
+ const valueStr = `${cellValue ?? ''}`;
+ return !valueStr || (valueStr === (`${formula1}`) || valueStr === `${formula2}`);
+ }
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule;
+ const formula1Success = !Tools.isBlank(formula1);
+ const formula2Success = !Tools.isBlank(formula2);
+
+ return {
+ success: formula1Success && formula2Success,
+ formula1: !formula1Success ? this.localeService.t('dataValidation.validFail.common') : '',
+ formula2: !formula2Success ? this.localeService.t('dataValidation.validFail.common') : '',
+ };
+ }
+
+ override async parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult> {
+ const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule;
+ const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
+ return {
+ formula1: isFormulaString(formula1) ? getFormulaResult(results?.[0]?.result) : formula1,
+ formula2: isFormulaString(formula2) ? getFormulaResult(results?.[1]?.result) : formula2,
+ };
+ }
+
+ 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);
+ return {
+ formula1: isFormulaString(formula1) ? getFormulaResult(results?.[0]?.result) : formula1,
+ formula2: isFormulaString(formula2) ? getFormulaResult(results?.[1]?.result) : formula2,
+ };
+ }
+
+ override async isValidType(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { value, unitId, subUnitId } = cellInfo;
+ const { formula1, formula2 } = await this.parseFormula(rule, unitId, subUnitId);
+ if (!Tools.isDefine(formula1) || !Tools.isDefine(formula2)) {
+ return true;
+ }
+
+ return Tools.isDefine(value) && (String(value) === String(formula1) || String(value) === String(formula2));
+ }
+
+ override generateRuleErrorMessage(rule: IDataValidationRuleBase): string {
+ return this.localeService.t('dataValidation.checkbox.error');
+ }
+}
diff --git a/packages/sheets-data-validation/src/validators/custom-validator.ts b/packages/sheets-data-validation/src/validators/custom-validator.ts
new file mode 100644
index 0000000000..38eb54b5cb
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/custom-validator.ts
@@ -0,0 +1,59 @@
+/**
+ * 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 { DataValidationType, isFormulaString } from '@univerjs/core';
+import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase } from '@univerjs/core';
+import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { BaseDataValidator } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { CUSTOM_FORMULA_INPUT_NAME } from '../views/formula-input';
+import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';
+import { getFormulaResult } from '../utils/formula';
+
+export class CustomFormulaValidator extends BaseDataValidator {
+ override id: string = DataValidationType.CUSTOM;
+ override title: string = 'dataValidation.custom.title';
+ override operators: DataValidationOperator[] = [];
+ override scopes: string | string[] = ['sheet'];
+ override formulaInput: string = CUSTOM_FORMULA_INPUT_NAME;
+
+ private _customFormulaService = this.injector.get(DataValidationCustomFormulaService);
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const success = isFormulaString(rule.formula1);
+ return {
+ success,
+ formula1: success ? '' : this.localeService.t('dataValidation.validFail.formula'),
+ };
+ }
+
+ override async parseFormula(_rule: IDataValidationRule, _unitId: string, _subUnitId: string): Promise<IFormulaResult> {
+ return {
+ formula1: undefined,
+ formula2: undefined,
+ };
+ }
+
+ override async isValidType(cellInfo: IValidatorCellInfo<CellValue>, _formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean> {
+ const { column, row, unitId, subUnitId } = cellInfo;
+ const result = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, row, column);
+
+ return Boolean(getFormulaResult(result?.result));
+ }
+
+ override generateRuleErrorMessage(rule: IDataValidationRuleBase): string {
+ return this.localeService.t('dataValidation.custom.error');
+ }
+}
diff --git a/packages/sheets-data-validation/src/validators/date-validator.ts b/packages/sheets-data-validation/src/validators/date-validator.ts
new file mode 100644
index 0000000000..e16daa1ebe
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/date-validator.ts
@@ -0,0 +1,238 @@
+/**
+ * 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 { DataValidationOperator, DataValidationType, isFormulaString, Tools } from '@univerjs/core';
+import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
+import type { Dayjs } from 'dayjs';
+import dayjs from 'dayjs';
+import type { IFormulaResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import { BaseDataValidator } from '@univerjs/data-validation';
+import type { IFormulaValidResult } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { BASE_FORMULA_INPUT_NAME } from '../views/formula-input';
+import { TWO_FORMULA_OPERATOR_COUNT } from '../types/const/two-formula-operators';
+import { serialTimeToTimestamp } from '../utils/date';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+import { getFormulaResult } from '../utils/formula';
+import { DATE_DROPDOWN_KEY } from '../views';
+
+const isValidDateString = (date: string) => {
+ return dayjs(date).isValid();
+};
+
+const transformDate = (value: Nullable<CellValue>) => {
+ if (value === undefined || value === null || typeof value === 'boolean') {
+ return undefined;
+ }
+
+ if (typeof value === 'number' || !Number.isNaN(+value)) {
+ return dayjs(serialTimeToTimestamp(+value));
+ }
+
+ return dayjs(value);
+};
+
+export class DateValidator extends BaseDataValidator<Dayjs> {
+ id: string = DataValidationType.DATE;
+ title: string = 'dataValidation.date.title';
+ operators: DataValidationOperator[] = [
+ DataValidationOperator.BETWEEN,
+ DataValidationOperator.EQUAL,
+ DataValidationOperator.GREATER_THAN,
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
+ DataValidationOperator.LESS_THAN,
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
+ DataValidationOperator.NOT_BETWEEN,
+ DataValidationOperator.NOT_EQUAL,
+ ];
+
+ scopes: string | string[] = ['sheet'];
+ formulaInput: string = BASE_FORMULA_INPUT_NAME;
+ override dropdown = DATE_DROPDOWN_KEY;
+
+ private _formulaService = this.injector.get(DataValidationFormulaService);
+
+ override async parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult<Dayjs | undefined>> {
+ const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
+ const { formula1, formula2 } = rule;
+
+ return {
+ formula1: transformDate(isFormulaString(formula1) ? getFormulaResult(results?.[0]?.result) : formula1),
+ formula2: transformDate(isFormulaString(formula2) ? getFormulaResult(results?.[1]?.result) : formula2),
+ };
+ }
+
+ transformDate = transformDate;
+
+ override async isValidType(info: IValidatorCellInfo): Promise<boolean> {
+ const { value } = info;
+ if (typeof value === 'string') {
+ return dayjs(value).isValid();
+ }
+
+ if (typeof value === 'number') {
+ return true;
+ }
+
+ return false;
+ }
+
+ private _validatorSingleFormula(formula: string | undefined) {
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula!) || (Boolean(formula) && dayjs(formula).isValid()));
+ }
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const operator = rule.operator;
+ if (!operator) {
+ return {
+ success: false,
+ };
+ }
+
+ const formula1Success = this._validatorSingleFormula(rule.formula1);
+ const errorMsg = this.localeService.t('dataValidation.validFail.date');
+ const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator);
+ if (isTwoFormula) {
+ const formula2Success = this._validatorSingleFormula(rule.formula2);
+ return {
+ success: formula1Success && formula2Success,
+ formula1: formula1Success ? undefined : errorMsg,
+ formula2: formula2Success ? undefined : errorMsg,
+ };
+ }
+
+ return {
+ success: formula1Success,
+ formula1: formula1Success ? undefined : errorMsg,
+ };
+ }
+
+ override transform(cellInfo: IValidatorCellInfo<CellValue>, _formula: IFormulaResult, _rule: IDataValidationRule): IValidatorCellInfo<Dayjs> {
+ const { value } = cellInfo;
+
+ return {
+ ...cellInfo,
+ value: transformDate(value)!,
+ };
+ }
+
+ override async validatorIsEqual(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>, _rule: IDataValidationRule): Promise<boolean> {
+ const { value } = info;
+ const { formula1 } = formula;
+ if (!formula1) {
+ return true;
+ }
+
+ return value.isSame(formula1);
+ }
+
+ override async validatorIsNotEqual(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>): Promise<boolean> {
+ const { value } = info;
+ const { formula1 } = formula;
+ if (!formula1) {
+ return true;
+ }
+
+ return !value.isSame(formula1);
+ }
+
+ override async validatorIsBetween(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>): Promise<boolean> {
+ const { value: cellValue } = info;
+ const { formula1: date1, formula2: date2 } = formula;
+ if (!date1 || !date2) {
+ return false;
+ }
+
+ const min = date1.isAfter(date2) ? date2 : date1;
+ const max = min === date1 ? date2 : date1;
+ return (cellValue.isAfter(min) || cellValue.isSame(min)) && (cellValue.isBefore(max) || cellValue.isSame(max));
+ }
+
+ override async validatorIsNotBetween(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>): Promise<boolean> {
+ const { value: cellValue } = info;
+ const { formula1: date1, formula2: date2 } = formula;
+ if (!date1 || !date2) {
+ return false;
+ }
+ const min = date1.isAfter(date2) ? date1 : date2;
+ const max = min === date1 ? date2 : date1;
+ return cellValue.isBefore(min) || cellValue.isAfter(max);
+ }
+
+ override async validatorIsGreaterThan(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>): Promise<boolean> {
+ const { value } = info;
+
+ const { formula1 } = formula;
+ if (!formula1) {
+ return true;
+ }
+ return value.isAfter(formula1);
+ }
+
+ override async validatorIsGreaterThanOrEqual(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>): Promise<boolean> {
+ const { value: cellValue } = info;
+
+ const { formula1 } = formula;
+ if (!formula1) {
+ return true;
+ }
+
+ return cellValue.isAfter(formula1) || cellValue.isSame(formula1);
+ }
+
+ override async validatorIsLessThan(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>): Promise<boolean> {
+ const { value: cellValue } = info;
+
+ const { formula1 } = formula;
+ if (!formula1) {
+ return true;
+ }
+
+ return cellValue.isBefore(formula1) || cellValue.isSame(formula1);
+ }
+
+ override async validatorIsLessThanOrEqual(info: IValidatorCellInfo<Dayjs>, formula: IFormulaResult<Dayjs | undefined>): Promise<boolean> {
+ const { value: cellValue } = info;
+
+ const { formula1 } = formula;
+ if (!formula1) {
+ return true;
+ }
+
+ return cellValue.isBefore(formula1) || cellValue.isSame(formula1);
+ }
+
+ validatorFormulaValue(rule: IDataValidationRuleBase): string | undefined {
+ if (!Tools.isDefine(rule.operator)) {
+ return undefined;
+ }
+
+ const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(rule.operator);
+
+ if (isTwoFormula) {
+ if (Tools.isBlank(rule.formula1) || Tools.isBlank(rule.formula2)) {
+ return '';
+ } else {
+ if (!isValidDateString(rule.formula1!) || !isValidDateString(rule.formula2!)) {
+ return '';
+ }
+ }
+ } else {
+ if (Tools.isBlank(rule.formula1)) {
+ return '';
+ }
+ }
+ }
+}
diff --git a/packages/sheets-data-validation/src/validators/decimal-validator.ts b/packages/sheets-data-validation/src/validators/decimal-validator.ts
new file mode 100644
index 0000000000..91758465fb
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/decimal-validator.ts
@@ -0,0 +1,197 @@
+/**
+ * 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 { DataValidationOperator, DataValidationType, isFormulaString, Tools } from '@univerjs/core';
+import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
+import type { IFormulaResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import { BaseDataValidator } from '@univerjs/data-validation';
+import type { IFormulaValidResult } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { BASE_FORMULA_INPUT_NAME } from '../views/formula-input';
+import { TWO_FORMULA_OPERATOR_COUNT } from '../types/const/two-formula-operators';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+
+export function getCellValueNumber(cellValue: CellValue) {
+ let str = cellValue;
+ if (typeof cellValue === 'string') {
+ if (cellValue.startsWith('¥') || cellValue.startsWith('$')) {
+ str = cellValue.slice(1);
+ }
+
+ return +str;
+ }
+
+ return +cellValue;
+}
+
+export class DecimalValidator extends BaseDataValidator<number> {
+ private _formulaService = this.injector.get(DataValidationFormulaService);
+
+ id: string = DataValidationType.DECIMAL;
+ title: string = this.localeService.t('dataValidation.decimal.title');
+
+ operators: DataValidationOperator[] = [
+ DataValidationOperator.BETWEEN,
+ DataValidationOperator.EQUAL,
+ DataValidationOperator.GREATER_THAN,
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
+ DataValidationOperator.LESS_THAN,
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
+ DataValidationOperator.NOT_BETWEEN,
+ DataValidationOperator.NOT_EQUAL,
+ ];
+
+ scopes: string | string[] = ['sheet'];
+ formulaInput: string = BASE_FORMULA_INPUT_NAME;
+ dropDownInput?: string;
+
+ private _isFormulaOrNumber(formula: string) {
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula));
+ }
+
+ override async isValidType(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule) {
+ const { value: cellValue } = cellInfo;
+
+ return !Number.isNaN(getCellValueNumber(cellValue));
+ }
+
+ override transform(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule) {
+ const { value: cellValue } = cellInfo;
+
+ return {
+ ...cellInfo,
+ value: getCellValueNumber(cellValue),
+ };
+ }
+
+ private _parseNumber(formula: Nullable<string | number | boolean>) {
+ if (formula === undefined || formula === null) {
+ return Number.NaN;
+ }
+
+ return +formula;
+ }
+
+ async parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string) {
+ const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
+ const { formula1, formula2 } = rule;
+
+ const info = {
+ formula1: this._parseNumber(isFormulaString(formula1) ? formulaInfo?.[0]?.result?.[0]?.[0]?.v : formula1),
+ formula2: this._parseNumber(isFormulaString(formula2) ? formulaInfo?.[1]?.result?.[0]?.[0]?.v : formula2),
+ };
+
+ return info;
+ }
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const operator = rule.operator;
+ if (!operator) {
+ return {
+ success: false,
+ };
+ }
+ const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrNumber(rule.formula1);
+ const formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrNumber(rule.formula2);
+ const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator);
+ const errorMsg = this.localeService.t('dataValidation.validFail.number');
+ if (isTwoFormula) {
+ return {
+ success: formula1Success && formula2Success,
+ formula1: formula1Success ? undefined : errorMsg,
+ formula2: formula2Success ? undefined : errorMsg,
+ };
+ }
+
+ return {
+ success: formula1Success,
+ formula1: formula1Success ? '' : errorMsg,
+ };
+ }
+
+ override async validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+
+ return cellValue === formula1;
+ }
+
+ override async validatorIsNotEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+
+ return cellInfo.value !== formula1;
+ }
+
+ override async validatorIsBetween(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1, formula2 } = formula;
+ if (Number.isNaN(formula1) || Number.isNaN(formula2)) {
+ return true;
+ }
+
+ const start = Math.min(formula1, formula2);
+ const end = Math.max(formula1, formula2);
+ return cellInfo.value >= start && cellInfo.value <= end;
+ }
+
+ override async validatorIsNotBetween(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1, formula2 } = formula;
+ if (Number.isNaN(formula1) || Number.isNaN(formula2)) {
+ return true;
+ }
+
+ const start = Math.min(formula1, formula2);
+ const end = Math.max(formula1, formula2);
+ return cellInfo.value < start && cellInfo.value > end;
+ }
+
+ override async validatorIsGreaterThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+ return cellInfo.value > formula1;
+ }
+
+ override async validatorIsGreaterThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+ return cellInfo.value >= formula1;
+ }
+
+ override async validatorIsLessThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+ return cellInfo.value < formula1;
+ }
+
+ override async validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+
+ return cellInfo.value <= formula1;
+ }
+}
diff --git a/packages/sheets-data-validation/src/validators/index.ts b/packages/sheets-data-validation/src/validators/index.ts
new file mode 100644
index 0000000000..ba6b4dee61
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/index.ts
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+export { CheckboxValidator, CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2 } from './checkbox-validator';
+export { DateValidator } from './date-validator';
+export { ListValidator } from './list-validator';
+export { DecimalValidator } from './decimal-validator';
+export { TextLengthValidator } from './text-length-validator';
diff --git a/packages/sheets-data-validation/src/validators/list-multiple-validator.ts b/packages/sheets-data-validation/src/validators/list-multiple-validator.ts
new file mode 100644
index 0000000000..9e3db5be35
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/list-multiple-validator.ts
@@ -0,0 +1,114 @@
+/**
+ * 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 { DataValidationType, IUniverInstanceService, Tools } from '@univerjs/core';
+import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
+import type { IFormulaResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import { BaseDataValidator } from '@univerjs/data-validation';
+import { deserializeRangeWithSheet, isReferenceString } from '@univerjs/engine-formula';
+import type { IFormulaValidResult } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { LIST_FORMULA_INPUT_NAME } from '../views/formula-input';
+import { LIST_DROPDOWN_KEY } from '../views';
+import { DropdownMultipleWidget } from '../widgets/dropdown-multiple-widget';
+import { deserializeListOptions, getSheetRangeValueSet } from './util';
+
+export class ListMultipleValidator extends BaseDataValidator {
+ id: string = DataValidationType.LIST_MULTIPLE;
+ title: string = 'dataValidation.listMultiple.title';
+ operators: DataValidationOperator[] = [];
+ scopes: string | string[] = ['sheet'];
+ formulaInput: string = LIST_FORMULA_INPUT_NAME;
+
+ private _univerInstanceService = this.injector.get(IUniverInstanceService);
+
+ override canvasRender = this.injector.createInstance(DropdownMultipleWidget);
+
+ override dropdown: string | undefined = LIST_DROPDOWN_KEY;
+
+ override skipDefaultFontRender() {
+ return true;
+ }
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const success = !Tools.isBlank(rule.formula1);
+
+ return {
+ success,
+ formula1: success ? undefined : this.localeService.t('dataValidation.validFail.list'),
+ };
+ }
+
+ parseCellValue(cellValue: CellValue, rule: IDataValidationRule) {
+ const cellString = cellValue.toString();
+ if (!cellString) {
+ return [];
+ }
+ return deserializeListOptions(cellString);
+ }
+
+ override async parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult<string[] | undefined>> {
+ const { formula1 = '' } = rule;
+
+ return {
+ formula1: isReferenceString(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1),
+ formula2: undefined,
+ };
+ }
+
+ override async isValidType(cellInfo: IValidatorCellInfo<Nullable<CellValue>>, formula: IFormulaResult<any>, rule: IDataValidationRule): Promise<boolean> {
+ const { value } = cellInfo;
+ const { formula1 } = formula;
+ const selected = this.parseCellValue(value!, rule);
+ return selected.every((i) => formula1.includes(i));
+ }
+
+ override generateRuleName() {
+ return this.localeService.t('dataValidation.list.name');
+ }
+
+ override generateRuleErrorMessage(): string {
+ return this.localeService.t('dataValidation.list.error');
+ }
+
+ getList(rule: IDataValidationRule, propUnitId?: string, propSubUnitId?: string) {
+ const { formula1 = '' } = rule;
+ const univerInstanceService = this.injector.get(IUniverInstanceService);
+ const workbook = (propUnitId ? univerInstanceService.getUniverSheetInstance(propUnitId) : undefined) ?? univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = (propSubUnitId ? workbook.getSheetBySheetId(propSubUnitId) : undefined) ?? workbook.getActiveSheet();
+ const unitId = workbook.getUnitId();
+ const subUnitId = worksheet.getSheetId();
+ return isReferenceString(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1);
+ }
+
+ getListWithColor(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {
+ const list = this.getList(rule, currentUnitId, currentSubUnitId);
+ const colorList = rule.formula2 ? rule.formula2.split(',') : [];
+
+ return list.map((label, i) => ({ label, color: colorList[i] }));
+ }
+
+ getListWithColorMap(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {
+ const list = this.getListWithColor(rule, currentUnitId, currentSubUnitId);
+ const map: Record<string, string> = {};
+
+ list.forEach((item) => {
+ if (item.color) {
+ map[item.label] = item.color;
+ }
+ });
+ return map;
+ }
+}
diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.ts
new file mode 100644
index 0000000000..9caedac7ca
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/list-validator.ts
@@ -0,0 +1,115 @@
+/**
+ * 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 { DataValidationType, IUniverInstanceService, Tools } from '@univerjs/core';
+import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase, ISheetDataValidationRule, Nullable } from '@univerjs/core';
+import type { IFormulaResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import { BaseDataValidator } from '@univerjs/data-validation';
+import { deserializeRangeWithSheet, isReferenceString } from '@univerjs/engine-formula';
+import type { IFormulaValidResult } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { DataValidationRenderMode } from '@univerjs/core/types/enum/data-validation-render-mode.js';
+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 { deserializeListOptions, getSheetRangeValueSet } from './util';
+
+export class ListValidator extends BaseDataValidator {
+ id: string = DataValidationType.LIST;
+ title: string = 'dataValidation.list.title';
+ operators: DataValidationOperator[] = [];
+ scopes: string | string[] = ['sheet'];
+ formulaInput: string = LIST_FORMULA_INPUT_NAME;
+
+ private _univerInstanceService = this.injector.get(IUniverInstanceService);
+
+ override canvasRender = this.injector.createInstance(DropdownWidget);
+
+ override dropdown: string | undefined = LIST_DROPDOWN_KEY;
+
+ override optionsInput: string | undefined = ListRenderModeInput.componentKey;
+
+ override skipDefaultFontRender(rule: ISheetDataValidationRule) {
+ return rule.renderMode !== DataValidationRenderMode.TEXT;
+ }
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const success = !Tools.isBlank(rule.formula1);
+
+ return {
+ success,
+ formula1: success ? undefined : this.localeService.t('dataValidation.validFail.list'),
+ };
+ }
+
+ private _parseCellValue(cellValue: CellValue, rule: IDataValidationRule) {
+ const cellString = cellValue.toString();
+ return deserializeListOptions(cellString);
+ }
+
+ override async parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult<string[] | undefined>> {
+ const { formula1 = '' } = rule;
+
+ return {
+ formula1: isReferenceString(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1),
+ formula2: undefined,
+ };
+ }
+
+ override async isValidType(cellInfo: IValidatorCellInfo<Nullable<CellValue>>, formula: IFormulaResult<any>, rule: IDataValidationRule): Promise<boolean> {
+ const { value } = cellInfo;
+ const { formula1 } = formula;
+ const selected = this._parseCellValue(value!, rule);
+ return selected.every((i) => formula1.includes(i));
+ }
+
+ override generateRuleName() {
+ return this.localeService.t('dataValidation.list.name');
+ }
+
+ override generateRuleErrorMessage(): string {
+ return this.localeService.t('dataValidation.list.error');
+ }
+
+ getList(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {
+ const { formula1 = '' } = rule;
+ const univerInstanceService = this.injector.get(IUniverInstanceService);
+ const workbook = (currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : undefined) ?? univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = (currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : undefined) ?? workbook.getActiveSheet();
+ const unitId = workbook.getUnitId();
+ const subUnitId = worksheet.getSheetId();
+ return isReferenceString(formula1) ? getSheetRangeValueSet(deserializeRangeWithSheet(formula1), this._univerInstanceService, unitId, subUnitId) : deserializeListOptions(formula1);
+ }
+
+ getListWithColor(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {
+ const list = this.getList(rule, currentUnitId, currentSubUnitId);
+ const colorList = (rule.formula2 || '').split(',');
+
+ return list.map((label, i) => ({ label, color: colorList[i] }));
+ }
+
+ getListWithColorMap(rule: IDataValidationRule, currentUnitId?: string, currentSubUnitId?: string) {
+ const list = this.getListWithColor(rule, currentUnitId, currentSubUnitId);
+ const map: Record<string, string> = {};
+
+ list.forEach((item) => {
+ if (item.color) {
+ map[item.label] = item.color;
+ }
+ });
+ return map;
+ }
+}
diff --git a/packages/sheets-data-validation/src/validators/text-length-validator.ts b/packages/sheets-data-validation/src/validators/text-length-validator.ts
new file mode 100644
index 0000000000..beb64a900e
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/text-length-validator.ts
@@ -0,0 +1,192 @@
+/**
+ * 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 { DataValidationOperator, DataValidationType, isFormulaString, Tools } from '@univerjs/core';
+import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
+import type { IFormulaResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import { BaseDataValidator } from '@univerjs/data-validation';
+import type { IFormulaValidResult } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { BASE_FORMULA_INPUT_NAME } from '../views/formula-input';
+import { TWO_FORMULA_OPERATOR_COUNT } from '../types/const/two-formula-operators';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+
+export class TextLengthValidator extends BaseDataValidator<number> {
+ id: string = DataValidationType.TEXT_LENGTH;
+ title: string = 'dataValidation.textLength.title';
+
+ operators: DataValidationOperator[] = [
+ DataValidationOperator.BETWEEN,
+ DataValidationOperator.EQUAL,
+ DataValidationOperator.GREATER_THAN,
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
+ DataValidationOperator.LESS_THAN,
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
+ DataValidationOperator.NOT_BETWEEN,
+ DataValidationOperator.NOT_EQUAL,
+ ];
+
+ scopes: string | string[] = ['sheet'];
+ formulaInput: string = BASE_FORMULA_INPUT_NAME;
+
+ private _formulaService = this.injector.get(DataValidationFormulaService);
+
+ private _isFormulaOrInt(formula: string) {
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || (!Number.isNaN(+formula) && Number.isInteger(+formula)));
+ }
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const operator = rule.operator;
+ if (!operator) {
+ return {
+ success: false,
+ };
+ }
+ const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1);
+ const formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2);
+ const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator);
+ const errorMsg = this.localeService.t('dataValidation.validFail.number');
+ if (isTwoFormula) {
+ return {
+ success: formula1Success && formula2Success,
+ formula1: formula1Success ? undefined : errorMsg,
+ formula2: formula2Success ? undefined : errorMsg,
+ };
+ }
+
+ return {
+ success: formula1Success,
+ formula1: errorMsg,
+ };
+ }
+
+ private _parseNumber(formula: Nullable<string | number | boolean>) {
+ if (formula === undefined || formula === null) {
+ return Number.NaN;
+ }
+
+ return +formula;
+ }
+
+ private _isValidFormula(formula: number) {
+ return !Number.isNaN(formula);
+ }
+
+ override async parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult<any>> {
+ const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
+ const { formula1, formula2 } = rule;
+
+ return {
+ formula1: this._parseNumber(isFormulaString(formula1) ? formulaInfo?.[0]?.result?.[0]?.[0]?.v : formula1),
+ formula2: this._parseNumber(isFormulaString(formula2) ? formulaInfo?.[1]?.result?.[0]?.[0]?.v : formula2),
+ };
+ }
+
+ override transform(cellInfo: IValidatorCellInfo<CellValue>, _formula: IFormulaResult, _rule: IDataValidationRule) {
+ return {
+ ...cellInfo,
+ value: cellInfo.value.toString().length,
+ };
+ }
+
+ override async isValidType(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule) {
+ const { value: cellValue } = cellInfo;
+ return typeof cellValue === 'string' || typeof cellValue === 'number';
+ }
+
+ override async validatorIsEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1 } = formula;
+ if (!Tools.isDefine(formula1)) {
+ return false;
+ }
+
+ return cellInfo.value === formula1;
+ }
+
+ override async validatorIsNotEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1 } = formula;
+ if (!Tools.isDefine(formula1)) {
+ return false;
+ }
+
+ return cellInfo.value !== formula1;
+ }
+
+ override async validatorIsBetween(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1, formula2 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (!this._isValidFormula(formula1) || !this._isValidFormula(formula2)) {
+ return false;
+ }
+
+ const max = Math.max(formula1, formula2);
+ const min = Math.min(formula1, formula2);
+
+ return cellValue >= min && cellValue <= max;
+ }
+
+ override async validatorIsNotBetween(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1, formula2 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (!this._isValidFormula(formula1) || !this._isValidFormula(formula2)) {
+ return false;
+ }
+
+ const max = Math.max(formula1, formula2);
+ const min = Math.min(formula1, formula2);
+
+ return cellValue >= min && cellValue <= max;
+ }
+
+ override async validatorIsGreaterThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (!this._isValidFormula(formula1)) {
+ return false;
+ }
+
+ return cellValue > formula1;
+ }
+
+ override async validatorIsGreaterThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (!this._isValidFormula(formula1)) {
+ return false;
+ }
+
+ return cellValue >= formula1;
+ }
+
+ override async validatorIsLessThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (!this._isValidFormula(formula1)) {
+ return false;
+ }
+
+ return cellValue < formula1;
+ }
+
+ override async validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
+ const { formula1 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (!this._isValidFormula(formula1)) {
+ return false;
+ }
+
+ return cellValue <= formula1;
+ }
+}
diff --git a/packages/sheets-data-validation/src/validators/util.ts b/packages/sheets-data-validation/src/validators/util.ts
new file mode 100644
index 0000000000..3bddef3ad8
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/util.ts
@@ -0,0 +1,65 @@
+/**
+ * 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 { Range } from '@univerjs/core';
+import type { ICellData, IUnitRangeName, IUniverInstanceService, Nullable } from '@univerjs/core';
+import { getCellValueOrigin } from '../utils/get-cell-data-origin';
+
+export function getSheetRangeValueSet(grid: IUnitRangeName, univerInstanceService: IUniverInstanceService, currUnitId: string, currSubUnitId: string) {
+ const set = new Set<string>();
+ const unitId = grid.unitId || currUnitId;
+ const workbook = univerInstanceService.getUniverSheetInstance(unitId) ?? univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getSheetBySheetName(grid.sheetName) ?? workbook.getSheetBySheetId(currSubUnitId) ?? workbook.getActiveSheet();
+ Range.foreach(grid.range, (row, col) => {
+ const data = worksheet.getCellRaw(row, col);
+ if (!data) {
+ return;
+ }
+
+ const cellValue = getCellValueOrigin(data);
+
+ if (cellValue === undefined || cellValue === null || cellValue === '') {
+ return;
+ }
+
+ const list = deserializeListOptions(`${cellValue}`);
+
+ list.forEach((item) => {
+ if (item) {
+ set.add(`${cellValue}`);
+ }
+ });
+ });
+
+ return Array.from(set);
+}
+
+export function serializeListOptions(options: string[]) {
+ return options.filter(Boolean).join(',');
+}
+
+export function deserializeListOptions(optionsStr: string) {
+ return optionsStr.split(',').filter(Boolean);
+}
+
+export function getDataValidationCellValue(cellData: Nullable<ICellData>) {
+ const cellValue = getCellValueOrigin(cellData);
+ if (cellValue === undefined || cellValue === null) {
+ return '';
+ }
+
+ return cellValue.toString();
+}
diff --git a/packages/sheets-data-validation/src/validators/whole-validator.ts b/packages/sheets-data-validation/src/validators/whole-validator.ts
new file mode 100644
index 0000000000..28d741f768
--- /dev/null
+++ b/packages/sheets-data-validation/src/validators/whole-validator.ts
@@ -0,0 +1,184 @@
+/**
+ * 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 { DataValidationOperator, DataValidationType, isFormulaString, Tools } from '@univerjs/core';
+import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
+import type { IFormulaResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import { BaseDataValidator } from '@univerjs/data-validation';
+import type { IFormulaValidResult } from '@univerjs/data-validation/validators/base-data-validator.js';
+import { BASE_FORMULA_INPUT_NAME } from '../views/formula-input';
+import { TWO_FORMULA_OPERATOR_COUNT } from '../types/const/two-formula-operators';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+import { getCellValueNumber } from './decimal-validator';
+
+export class WholeValidator extends BaseDataValidator<number> {
+ private _formulaService = this.injector.get(DataValidationFormulaService);
+
+ id: string = DataValidationType.WHOLE;
+ title: string = this.localeService.t('dataValidation.whole.title');
+
+ operators: DataValidationOperator[] = [
+ DataValidationOperator.BETWEEN,
+ DataValidationOperator.EQUAL,
+ DataValidationOperator.GREATER_THAN,
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
+ DataValidationOperator.LESS_THAN,
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
+ DataValidationOperator.NOT_BETWEEN,
+ DataValidationOperator.NOT_EQUAL,
+ ];
+
+ scopes: string | string[] = ['sheet'];
+ formulaInput: string = BASE_FORMULA_INPUT_NAME;
+ dropDownInput?: string;
+
+ private _isFormulaOrInt(formula: string) {
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || (!Number.isNaN(+formula) && Number.isInteger(+formula)));
+ }
+
+ override async isValidType(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule) {
+ const { value: cellValue } = cellInfo;
+ const num = getCellValueNumber(cellValue);
+ return !Number.isNaN(num) && Number.isInteger(num);
+ }
+
+ override transform(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule) {
+ const { value: cellValue } = cellInfo;
+ return {
+ ...cellInfo,
+ value: getCellValueNumber(cellValue),
+ };
+ }
+
+ private _parseNumber(formula: Nullable<string | number | boolean>) {
+ if (formula === undefined || formula === null) {
+ return Number.NaN;
+ }
+
+ return +formula;
+ }
+
+ async parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string) {
+ const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
+ const { formula1, formula2 } = rule;
+
+ const info = {
+ formula1: this._parseNumber(isFormulaString(formula1) ? formulaInfo?.[0]?.result?.[0]?.[0]?.v : formula1),
+ formula2: this._parseNumber(isFormulaString(formula2) ? formulaInfo?.[1]?.result?.[0]?.[0]?.v : formula2),
+ };
+
+ return info;
+ }
+
+ override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ const operator = rule.operator;
+ if (!operator) {
+ return {
+ success: false,
+ };
+ }
+ const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1);
+ const formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2);
+ const isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator);
+ const errorMsg = this.localeService.t('dataValidation.validFail.number');
+ if (isTwoFormula) {
+ return {
+ success: formula1Success && formula2Success,
+ formula1: formula1Success ? undefined : errorMsg,
+ formula2: formula2Success ? undefined : errorMsg,
+ };
+ }
+
+ return {
+ success: formula1Success,
+ formula1: errorMsg,
+ };
+ }
+
+ override async validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ const { value: cellValue } = cellInfo;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+
+ return cellValue === formula1;
+ }
+
+ override async validatorIsNotEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+
+ return cellInfo.value !== formula1;
+ }
+
+ override async validatorIsBetween(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1, formula2 } = formula;
+ if (Number.isNaN(formula1) || Number.isNaN(formula2)) {
+ return true;
+ }
+
+ const start = Math.min(formula1, formula2);
+ const end = Math.max(formula1, formula2);
+ return cellInfo.value >= start && cellInfo.value <= end;
+ }
+
+ override async validatorIsNotBetween(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1, formula2 } = formula;
+ if (Number.isNaN(formula1) || Number.isNaN(formula2)) {
+ return true;
+ }
+
+ const start = Math.min(formula1, formula2);
+ const end = Math.max(formula1, formula2);
+ return cellInfo.value < start && cellInfo.value > end;
+ }
+
+ override async validatorIsGreaterThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+ return cellInfo.value > formula1;
+ }
+
+ override async validatorIsGreaterThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+ return cellInfo.value >= formula1;
+ }
+
+ override async validatorIsLessThan(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+ return cellInfo.value < formula1;
+ }
+
+ override async validatorIsLessThanOrEqual(cellInfo: IValidatorCellInfo<number>, formula: IFormulaResult, _rule: IDataValidationRule) {
+ const { formula1 } = formula;
+ if (Number.isNaN(formula1)) {
+ return true;
+ }
+
+ return cellInfo.value <= formula1;
+ }
+}
diff --git a/packages/sheets-data-validation/src/views/date-dropdown/index.module.less b/packages/sheets-data-validation/src/views/date-dropdown/index.module.less
new file mode 100644
index 0000000000..e1aaa1ee7e
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/date-dropdown/index.module.less
@@ -0,0 +1,6 @@
+.dv-date-dropdown {
+ background: #fff;
+ border-radius: var(--border-radius-base);
+ box-shadow: var(--box-shadow-lg);
+ padding: var(--padding-sm);
+}
diff --git a/packages/sheets-data-validation/src/views/date-dropdown/index.tsx b/packages/sheets-data-validation/src/views/date-dropdown/index.tsx
new file mode 100644
index 0000000000..b4915ca836
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/date-dropdown/index.tsx
@@ -0,0 +1,81 @@
+/**
+ * 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 React, { useState } from 'react';
+import { ICommandService } from '@univerjs/core';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { DatePanel } from '@univerjs/design';
+import { SetRangeValuesCommand } from '@univerjs/sheets';
+import dayjs from 'dayjs';
+import type { IDropdownComponentProps } from '../../services/dropdown-manager.service';
+import type { DateValidator } from '../../validators';
+import { getCellValueOrigin } from '../../utils/get-cell-data-origin';
+import styles from './index.module.less';
+
+export function DateDropdown(props: IDropdownComponentProps) {
+ const { location, hideFn } = props;
+ const { worksheet, row, col, unitId, subUnitId } = location;
+ const commandService = useDependency(ICommandService);
+ const [localDate, setLocalDate] = useState<dayjs.Dayjs>();
+ if (!worksheet) {
+ return null;
+ }
+
+ const cellData = worksheet.getCell(row, col);
+ const rule = cellData?.dataValidation?.rule;
+ const validator = cellData?.dataValidation?.validator as DateValidator | undefined;
+
+ if (!cellData || !rule || !validator) {
+ return;
+ }
+
+ const cellStr = getCellValueOrigin(cellData);
+ const originDate = validator.transformDate(cellStr) ?? dayjs();
+ const date = originDate.isValid() ? originDate : dayjs();
+
+ return (
+ <div className={styles.dvDateDropdown}>
+ <DatePanel
+ pickerValue={localDate ?? date}
+ onSelect={(newValue) => {
+ const newValueStr = newValue.format('YYYY/MM/DD');
+ commandService.executeCommand(SetRangeValuesCommand.id, {
+ unitId,
+ subUnitId,
+ range: {
+ startColumn: col,
+ endColumn: col,
+ startRow: row,
+ endRow: row,
+ },
+ value: {
+ v: newValueStr,
+ p: null,
+ f: null,
+ si: null,
+
+ },
+ });
+ hideFn();
+ }}
+ onPanelChange={(value) => {
+ setLocalDate(value);
+ }}
+ />
+ </div>
+
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/detail/index.module.less b/packages/sheets-data-validation/src/views/detail/index.module.less
new file mode 100644
index 0000000000..c48602a957
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/detail/index.module.less
@@ -0,0 +1,16 @@
+.data-validation-detail {
+ &-form-item {
+ width: 100%;
+ }
+
+ &-buttons {
+ margin-top: 20px;
+ display: flex;
+ flex-direction: row;
+ justify-content: flex-end;
+ }
+
+ &-button {
+ margin-left: 12px;
+ }
+}
diff --git a/packages/sheets-data-validation/src/views/detail/index.tsx b/packages/sheets-data-validation/src/views/detail/index.tsx
new file mode 100644
index 0000000000..698b53d507
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/detail/index.tsx
@@ -0,0 +1,293 @@
+/**
+ * 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 type { DataValidationOperator, IDataValidationRuleBase, IDataValidationRuleOptions, IExecutionOptions, ISheetDataValidationRule, IUnitRange } from '@univerjs/core';
+import { DataValidationType, debounce, ICommandService, isUnitRangesEqual, isValidRange, LocaleService, RedoCommand, shallowEqual, UndoCommand } from '@univerjs/core';
+import type { IUpdateDataValidationSettingCommandParams } from '@univerjs/data-validation';
+import { DataValidationModel, DataValidatorRegistryScope, DataValidatorRegistryService, RemoveDataValidationCommand, UpdateDataValidationOptionsCommand, UpdateDataValidationSettingCommand } from '@univerjs/data-validation';
+import { TWO_FORMULA_OPERATOR_COUNT } from '@univerjs/data-validation/types/const/two-formula-operators.js';
+import { Button, FormLayout, Select } from '@univerjs/design';
+import { ComponentManager, RangeSelector, useEvent, useObservable } from '@univerjs/ui';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import React, { useEffect, useMemo, useState } from 'react';
+import { serializeRange } from '@univerjs/engine-formula';
+import { getRuleOptions, getRuleSetting } from '@univerjs/data-validation/common/util.js';
+import type { IUpdateSheetDataValidationRangeCommandParams } from '../../commands/commands/data-validation.command';
+import { UpdateSheetDataValidationRangeCommand } from '../../commands/commands/data-validation.command';
+import { DataValidationOptions } from '../options';
+import { DataValidationPanelService } from '../../services/data-validation-panel.service';
+import styles from './index.module.less';
+
+// debounce execute commands, for better redo-undo experience
+const debounceExecuteFactory = (commandService: ICommandService) => debounce(
+ async (id: string, params?: any, options?: IExecutionOptions | undefined,
+ callback?: (success: boolean) => void
+ ) => {
+ const res = await commandService.executeCommand(id, params, options);
+ callback?.(res);
+ }
+ ,
+ 275
+);
+
+export function DataValidationDetail() {
+ const [key, setKey] = useState(0);
+ const dataValidationPanelService = useDependency(DataValidationPanelService);
+ const activeRuleInfo = useObservable(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule)!;
+ const { unitId, subUnitId, rule } = activeRuleInfo || {};
+ const ruleId = rule.uid;
+ const validatorService = useDependency(DataValidatorRegistryService);
+ const componentManager = useDependency(ComponentManager);
+ const commandService = useDependency(ICommandService);
+ const dataValidationModel = useDependency(DataValidationModel);
+ const localeService = useDependency(LocaleService);
+ const [localRule, setLocalRule] = useState<ISheetDataValidationRule>(rule);
+ const validator = validatorService.getValidatorItem(localRule.type);
+ const [showError, setShowError] = useState(false);
+ const validators = validatorService.getValidatorsByScope(DataValidatorRegistryScope.SHEET);
+ const [localRanges, setLocalRanges] = useState<IUnitRange[]>(() => localRule.ranges.map((i) => ({ unitId: '', sheetId: '', range: i })));
+ const debounceExecute = useMemo(() => debounceExecuteFactory(commandService), [commandService]);
+
+ useEffect(() => {
+ commandService.onCommandExecuted((commandInfo) => {
+ if (commandInfo.id === UndoCommand.id || commandInfo.id === RedoCommand.id) {
+ setTimeout(() => {
+ const activeRule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId) as ISheetDataValidationRule;
+ setKey((k) => k + 1);
+ if (activeRule) {
+ setLocalRule(activeRule);
+ setLocalRanges(activeRule.ranges.map((i) => ({ unitId: '', sheetId: '', range: i })));
+ }
+ }, 20);
+ }
+ });
+ }, [commandService, dataValidationModel, ruleId, subUnitId, unitId]);
+
+ if (!validator) {
+ return null;
+ }
+
+ const operators = validator.operators;
+ const operatorNames = validator.operatorNames;
+ const isTwoFormula = localRule.operator ? TWO_FORMULA_OPERATOR_COUNT.includes(localRule.operator) : false;
+
+ const handleOk = () => {
+ if (validator.validatorFormula(localRule).success) {
+ dataValidationPanelService.setActiveRule(null);
+ } else {
+ setShowError(true);
+ }
+ };
+
+ const handleUpdateRuleRanges = useEvent((unitRanges: IUnitRange[]) => {
+ if (isUnitRangesEqual(unitRanges, localRanges)) {
+ return;
+ }
+ setLocalRanges(unitRanges);
+ const ranges = unitRanges.filter((i) => (!i.unitId || i.unitId === unitId) && (!i.sheetId || i.sheetId === subUnitId)).map((i) => i.range);
+
+ setLocalRule({
+ ...localRule,
+ ranges,
+ });
+ const params: IUpdateSheetDataValidationRangeCommandParams = {
+ unitId,
+ subUnitId,
+ ruleId,
+ ranges,
+ };
+
+ debounceExecute(UpdateSheetDataValidationRangeCommand.id, params);
+ });
+
+ const handleUpdateRuleSetting = (setting: IDataValidationRuleBase) => {
+ if (shallowEqual(setting, getRuleSetting(localRule))) {
+ return;
+ }
+
+ setLocalRule({
+ ...localRule,
+ ...setting,
+ });
+ const params: IUpdateDataValidationSettingCommandParams = {
+ unitId,
+ subUnitId,
+ ruleId,
+ setting,
+ };
+
+ debounceExecute(
+ UpdateDataValidationSettingCommand.id,
+ params,
+ undefined
+ );
+ };
+
+ const handleDelete = async () => {
+ await commandService.executeCommand(RemoveDataValidationCommand.id, {
+ ruleId,
+ unitId,
+ subUnitId,
+ });
+ dataValidationPanelService.setActiveRule(null);
+ };
+
+ const baseRule = {
+ type: localRule.type,
+ operator: localRule.operator,
+ formula1: localRule.formula1,
+ formula2: localRule.formula2,
+ allowBlank: localRule.allowBlank,
+ };
+
+ const handleChangeType = (newType: string) => {
+ const validator = validatorService.getValidatorItem(newType);
+ if (!validator) {
+ return;
+ }
+
+ const operators = validator.operators;
+
+ const newRule = {
+ ...localRule,
+ type: newType as DataValidationType,
+ operator: operators[0],
+ ...(newType === DataValidationType.CHECKBOX
+ ? {
+ formula1: undefined,
+ formula2: undefined,
+ }
+ : null),
+ };
+ setLocalRule(newRule);
+
+ commandService.executeCommand(UpdateDataValidationSettingCommand.id, {
+ unitId,
+ subUnitId,
+ ruleId: localRule.uid,
+ setting: getRuleSetting(newRule),
+ });
+ };
+
+ const FormulaInput = componentManager.get(validator.formulaInput);
+ const rangeStr = localRanges.map((i) => serializeRange(i.range)).join(',');
+
+ const options: IDataValidationRuleOptions = getRuleOptions(localRule);
+
+ const handleUpdateRuleOptions = (newOptions: IDataValidationRuleOptions) => {
+ if (shallowEqual(newOptions, getRuleOptions(localRule))) {
+ return;
+ }
+ setLocalRule({
+ ...localRule,
+ ...newOptions,
+ });
+
+ debounceExecute(
+ UpdateDataValidationOptionsCommand.id,
+ {
+ unitId,
+ subUnitId,
+ ruleId,
+ options: newOptions,
+ }
+ );
+ };
+ return (
+ <div>
+ <FormLayout label={localeService.t('dataValidation.panel.range')}>
+ <RangeSelector
+ key={key}
+ className={styles.dataValidationDetailFormItem}
+ value={rangeStr}
+ id="data-validation-detail"
+ openForSheetUnitId={unitId}
+ openForSheetSubUnitId={subUnitId}
+ onChange={(newRange) => {
+ if (newRange.some((i) => !isValidRange(i.range) || i.range.endColumn < i.range.startColumn || i.range.endRow < i.range.startRow)) {
+ return;
+ }
+
+ handleUpdateRuleRanges(newRange);
+ }}
+
+ />
+ </FormLayout>
+ <FormLayout label={localeService.t('dataValidation.panel.type')}>
+ <Select
+ options={validators?.map((validator) => ({
+ label: localeService.t(validator.title),
+ value: validator.id,
+ }))}
+ value={localRule.type}
+ onChange={handleChangeType}
+ className={styles.dataValidationDetailFormItem}
+ />
+ </FormLayout>
+ {operators?.length
+ ? (
+ <FormLayout label={localeService.t('dataValidation.panel.operator')}>
+ <Select
+ options={operators.map((op, i) => ({
+ value: `${op}`,
+ label: operatorNames[i],
+ }))}
+ value={`${localRule.operator}`}
+ onChange={(operator) => {
+ handleUpdateRuleSetting({
+ ...baseRule,
+ operator: operator as DataValidationOperator,
+ });
+ }}
+ className={styles.dataValidationDetailFormItem}
+ />
+ </FormLayout>
+ )
+ : null}
+ {FormulaInput
+ ? (
+ <FormulaInput
+ key={key}
+ isTwoFormula={isTwoFormula}
+ value={{
+ formula1: localRule.formula1,
+ formula2: localRule.formula2,
+ }}
+ onChange={(value: any) => {
+ handleUpdateRuleSetting({
+ ...baseRule,
+ ...value,
+ });
+ }}
+ showError={showError}
+ validResult={validator.validatorFormula(localRule)}
+ unitId={unitId}
+ subUnitId={subUnitId}
+ />
+ )
+ : null}
+ <DataValidationOptions value={options} onChange={handleUpdateRuleOptions} extraComponent={validator.optionsInput} />
+ <div className={styles.dataValidationDetailButtons}>
+ <Button className={styles.dataValidationDetailButton} onClick={handleDelete}>
+ {localeService.t('dataValidation.panel.removeRule')}
+ </Button>
+ <Button className={styles.dataValidationDetailButton} type="primary" onClick={handleOk}>
+ {localeService.t('dataValidation.panel.done')}
+ </Button>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/drop-down/CellDropdown.tsx b/packages/sheets-data-validation/src/views/drop-down/CellDropdown.tsx
new file mode 100644
index 0000000000..016390bc12
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/drop-down/CellDropdown.tsx
@@ -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 { useDependency } from '@wendellhu/redi/react-bindings';
+import { ComponentManager, useObservable } from '@univerjs/ui';
+import React from 'react';
+import { DataValidationDropdownManagerService } from '../../services/dropdown-manager.service';
+
+export function CellDropdown() {
+ const dropdownManagerService = useDependency(DataValidationDropdownManagerService);
+ const activeDropdown = useObservable(dropdownManagerService.activeDropdown$, dropdownManagerService.activeDropdown);
+ const componentManager = useDependency(ComponentManager);
+
+ if (!activeDropdown) {
+ return null;
+ }
+
+ const { location, componentKey } = activeDropdown;
+ const Component = componentManager.get(componentKey);
+
+ const key = `${location.unitId}-${location.subUnitId}-${location.row}-${location.col}`;
+
+ if (!Component) {
+ return null;
+ }
+
+ const hideFn = () => {
+ dropdownManagerService.hideDropdown();
+ };
+
+ return (
+ <Component
+ key={key}
+ location={location}
+ hideFn={hideFn}
+ />
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/drop-down/index.ts b/packages/sheets-data-validation/src/views/drop-down/index.ts
new file mode 100644
index 0000000000..dead304b81
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/drop-down/index.ts
@@ -0,0 +1,19 @@
+/**
+ * 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.
+ */
+
+export { CellDropdown } from './CellDropdown';
+const DROP_DOWN_KEY = 'sheet.ui.dropdown';
+export { DROP_DOWN_KEY };
diff --git a/packages/sheets-data-validation/src/views/formula-input/base-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/base-formula-input.tsx
new file mode 100644
index 0000000000..eae38f935c
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/formula-input/base-formula-input.tsx
@@ -0,0 +1,78 @@
+/**
+ * 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 type { IFormulaInputProps } from '@univerjs/data-validation';
+import { FormLayout, Input } from '@univerjs/design';
+import React from 'react';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { LocaleService } from '@univerjs/core';
+import styles from './index.module.less';
+
+export const BaseFormulaInput = (props: IFormulaInputProps) => {
+ const { isTwoFormula = false, value, onChange, showError, validResult } = props;
+ const localeService = useDependency(LocaleService);
+ const formula1Res = showError ? validResult?.formula1 : '';
+ const formula2Res = showError ? validResult?.formula2 : '';
+
+ if (isTwoFormula) {
+ return (
+ <>
+ <FormLayout error={formula1Res}>
+ <Input
+ className={styles.dataValidationFormula}
+ placeholder={localeService.t('dataValidation.panel.formulaPlaceholder')}
+ value={value?.formula1}
+ onChange={(newValue) => {
+ onChange?.({
+ ...value,
+ formula1: newValue,
+ });
+ }}
+ />
+ </FormLayout>
+ <div className={styles.dataValidationFormulaAnd}>
+ {localeService.t('dataValidation.panel.formulaAnd')}
+ </div>
+ <FormLayout error={formula2Res}>
+ <Input
+ className={styles.dataValidationFormula}
+ placeholder={localeService.t('dataValidation.panel.formulaPlaceholder')}
+ value={value?.formula2}
+ onChange={(newValue) => {
+ onChange?.({
+ ...value,
+ formula2: newValue,
+ });
+ }}
+ />
+ </FormLayout>
+ </>
+ );
+ }
+
+ return (
+ <FormLayout error={formula1Res}>
+ <Input
+ className={styles.dataValidationFormula}
+ placeholder={localeService.t('dataValidation.panel.formulaPlaceholder')}
+ value={value?.formula1}
+ onChange={(newValue) => {
+ onChange?.({ formula1: newValue });
+ }}
+ />
+ </FormLayout>
+ );
+};
diff --git a/packages/sheets-data-validation/src/views/formula-input/checkbox-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/checkbox-formula-input.tsx
new file mode 100644
index 0000000000..bb93a67c9f
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/formula-input/checkbox-formula-input.tsx
@@ -0,0 +1,89 @@
+/**
+ * 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 { LocaleService } from '@univerjs/core';
+import type { IFormulaInputProps } from '@univerjs/data-validation';
+import { Checkbox, FormLayout, Input } from '@univerjs/design';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import React, { useState } from 'react';
+import styles from './index.module.less';
+
+export function CheckboxFormulaInput(props: IFormulaInputProps) {
+ const { value, onChange, showError, validResult } = props;
+ const localeService = useDependency(LocaleService);
+ const formula1Res = showError ? validResult?.formula1 : '';
+ const formula2Res = showError ? validResult?.formula2 : '';
+
+ const [checked, setChecked] = useState(!(value?.formula1 === undefined && value?.formula2 === undefined));
+
+ return (
+ <>
+ <FormLayout>
+ <Checkbox
+ checked={checked}
+ onChange={(newValue) => {
+ if (newValue) {
+ setChecked(true);
+ } else {
+ setChecked(false);
+ onChange?.({
+ ...value,
+ formula1: undefined,
+ formula2: undefined,
+ });
+ }
+ }}
+ >
+ {localeService.t('dataValidation.checkbox.tips')}
+ </Checkbox>
+ </FormLayout>
+ {checked
+ ? (
+ <FormLayout label={localeService.t('dataValidation.checkbox.checked')} error={formula1Res}>
+ <Input
+ className={styles.dataValidationFormula}
+ placeholder={localeService.t('dataValidation.panel.formulaPlaceholder')}
+ value={value?.formula1}
+ onChange={(newValue) => {
+ onChange?.({
+ ...value,
+ formula1: newValue,
+ });
+ }}
+ />
+ </FormLayout>
+ )
+ : null}
+ {checked
+ ? (
+ <FormLayout label={localeService.t('dataValidation.checkbox.unchecked')} error={formula2Res}>
+ <Input
+ className={styles.dataValidationFormula}
+ placeholder={localeService.t('dataValidation.panel.formulaPlaceholder')}
+ value={value?.formula2}
+ onChange={(newValue) => {
+ onChange?.({
+ ...value,
+ formula2: newValue,
+ });
+ }}
+ />
+ </FormLayout>
+ )
+ : null}
+ </>
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
new file mode 100644
index 0000000000..46aa009d17
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
@@ -0,0 +1,42 @@
+/**
+ * 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 { FormLayout } from '@univerjs/design';
+import React from 'react';
+
+import { TextEditor } from '@univerjs/ui';
+import type { IFormulaInputProps } from '@univerjs/data-validation/types/interfaces/i-formula-input.js';
+
+export function CustomFormulaInput(props: IFormulaInputProps) {
+ const { unitId, subUnitId, value, onChange, showError, validResult } = props;
+ const formula1Res = showError ? validResult?.formula1 : '';
+
+ return (
+ <FormLayout error={formula1Res}>
+ <TextEditor
+ value={value?.formula1 ?? ''}
+ id={`dataValidation-custom-formula-${unitId}-${subUnitId}`}
+ onChange={(newValue) => {
+ onChange?.({
+ ...value,
+ formula1: newValue ?? '',
+ });
+ }}
+ onlyInputFormula
+ />
+ </FormLayout>
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/formula-input/formula-input.ts b/packages/sheets-data-validation/src/views/formula-input/formula-input.ts
new file mode 100644
index 0000000000..0832094ad1
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/formula-input/formula-input.ts
@@ -0,0 +1,33 @@
+/**
+ * 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 type { FormulaInputType } from '@univerjs/data-validation';
+import { BaseFormulaInput } from './base-formula-input';
+import { ListFormulaInput } from './list-formula-input';
+
+export const BASE_FORMULA_INPUT_NAME = 'data-validation.formula-input';
+export const LIST_FORMULA_INPUT_NAME = 'data-validation.list-formula-input';
+
+export const FORMULA_INPUTS: [string, FormulaInputType][] = [
+ [
+ BASE_FORMULA_INPUT_NAME,
+ BaseFormulaInput,
+ ],
+ [
+ LIST_FORMULA_INPUT_NAME,
+ ListFormulaInput,
+ ],
+];
diff --git a/packages/sheets-data-validation/src/views/formula-input/index.module.less b/packages/sheets-data-validation/src/views/formula-input/index.module.less
new file mode 100644
index 0000000000..61fda630e3
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/formula-input/index.module.less
@@ -0,0 +1,85 @@
+.data-validation-formula {
+ width: 100%;
+
+ &-and {
+ margin-top: -4px;
+ font-size: var(--font-size-sm);
+ color: rgba(var(--grey-400));
+ }
+
+ &-list-item {
+ display: flex;
+ padding-bottom: 2px;
+ align-items: center;
+
+ &-icon {
+ font-size: 16px;
+ cursor: pointer;
+ margin-left: 4px;
+ border-radius: 4px;
+ }
+
+ &-icon:hover {
+ background: rgba(var(--grey-100));
+ }
+
+ &-drag {
+ cursor: move;
+ }
+ }
+
+ &-list-add {
+ color: #274fee;
+ font-size: 13px;
+ font-weight: 400;
+ cursor: pointer;
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ border-radius: 4px;
+ padding: 4px 8px;
+ width: fit-content;
+
+ svg {
+ margin-right: 4px;
+ }
+ }
+
+ &-list-add:hover {
+ background: rgba(39, 79, 238, 0.05);
+ }
+
+ &-color-select {
+ width: 92px;
+ margin-left: 4px;
+ margin-right: 8px;
+ height: 31px;
+ }
+
+ &-color-select-panel {
+ width: 112px;
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ padding: 12px 4px 4px 12px;
+ flex-wrap: wrap;
+ box-sizing: border-box;
+
+ .data-validation-formula-color-item {
+ margin-bottom: 8px;
+ margin-right: 8px;
+ box-sizing: border-box;
+ cursor: pointer;
+ }
+ }
+
+ &-color-item {
+ border-radius: 3px;
+ border: 1px solid rgba(var(--grey-400));
+ width: 16px;
+ height: 16px;
+ box-sizing: border-box;
+ font-size: 16px;
+ margin-top: 2px;
+ }
+}
diff --git a/packages/sheets-data-validation/src/views/formula-input/index.ts b/packages/sheets-data-validation/src/views/formula-input/index.ts
new file mode 100644
index 0000000000..dcd63e964e
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/formula-input/index.ts
@@ -0,0 +1,44 @@
+/**
+ * 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 type { FormulaInputType } from '@univerjs/data-validation';
+import { CustomFormulaInput } from './custom-formula-input';
+import { BaseFormulaInput } from './base-formula-input';
+import { ListFormulaInput } from './list-formula-input';
+import { CheckboxFormulaInput } from './checkbox-formula-input';
+
+export const CUSTOM_FORMULA_INPUT_NAME = 'data-validation.custom-formula-input';
+export const BASE_FORMULA_INPUT_NAME = 'data-validation.formula-input';
+export const LIST_FORMULA_INPUT_NAME = 'data-validation.list-formula-input';
+export const CHECKBOX_FORMULA_INPUT_NAME = 'data-validation.checkbox-formula-input';
+
+export const FORMULA_INPUTS: [string, FormulaInputType][] = [[
+ CUSTOM_FORMULA_INPUT_NAME,
+ CustomFormulaInput,
+],
+[
+ BASE_FORMULA_INPUT_NAME,
+ BaseFormulaInput,
+],
+[
+ LIST_FORMULA_INPUT_NAME,
+ ListFormulaInput,
+],
+[
+ CHECKBOX_FORMULA_INPUT_NAME,
+ CheckboxFormulaInput,
+],
+];
diff --git a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
new file mode 100644
index 0000000000..92af019f3f
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
@@ -0,0 +1,351 @@
+/**
+ * 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 { RangeSelector, useEvent } from '@univerjs/ui';
+import React, { useEffect, useMemo, useRef, useState } from 'react';
+import { FormLayout, Input, Radio, RadioGroup, Select } from '@univerjs/design';
+import { deserializeRangeWithSheet, isReferenceString, serializeRangeWithSheet } from '@univerjs/engine-formula';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import type { IRange } from '@univerjs/core';
+import { IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
+import type { IFormulaInputProps } from '@univerjs/data-validation';
+import { DeleteSingle, IncreaseSingle, SequenceSingle } from '@univerjs/icons';
+import DraggableList from 'react-draggable-list';
+import { deserializeListOptions, getSheetRangeValueSet, serializeListOptions } from '../../validators/util';
+import { DROP_DOWN_DEFAULT_COLOR } from '../../common/const';
+import styles from './index.module.less';
+
+function isRangeInValid(range: IRange) {
+ return Number.isNaN(range.startColumn) || Number.isNaN(range.endColumn) || Number.isNaN(range.startRow) || Number.isNaN(range.endRow);
+}
+
+const DEFAULT_COLOR_PRESET = [
+ '#FFFFFF',
+ '#FEE7E7',
+ '#FEF0E6',
+ '#EFFBD0',
+ '#E4F4FE',
+ '#E8ECFD',
+ '#F1EAFA',
+ '#FDE8F3',
+ '#E5E5E5',
+ '#FDCECE',
+ '#FDC49B',
+ '#DEF6A2',
+ '#9FDAFF',
+ '#D0D9FB',
+ '#E3D5F6',
+ '#FBD0E8',
+ '#656565',
+ '#FE4B4B',
+ '#FF8C51',
+ '#8BBB11',
+ '#0B9EFB',
+ '#3A60F7',
+ '#9E6DE3',
+ '#F248A6',
+];
+
+interface IDropdownItem {
+ color: string;
+ label: string;
+ isRef: boolean;
+ id: string;
+}
+
+interface IColorSelectProps {
+ value: string;
+ onChange: (value: string) => void;
+ disabled?: boolean;
+}
+
+const ColorSelect = (props: IColorSelectProps) => {
+ const { value, onChange, disabled } = props;
+ const [open, setOpen] = useState(false);
+ return (
+ <Select
+ disabled={disabled}
+ open={open}
+ onDropdownVisibleChange={setOpen}
+ dropdownStyle={{ width: 112 }}
+ className={styles.dataValidationFormulaColorSelect}
+ value={value}
+ onChange={onChange}
+ labelRender={(item) => <div className={styles.dataValidationFormulaColorItem} style={{ background: item.value }} />}
+ dropdownRender={() => {
+ return (
+ <div className={styles.dataValidationFormulaColorSelectPanel}>
+ {DEFAULT_COLOR_PRESET.map(
+ (color) => (
+ <div
+ onClick={() => {
+ onChange(color);
+ setOpen(false);
+ }}
+ className={styles.dataValidationFormulaColorItem}
+ style={{ background: color }}
+ key={color}
+ />
+ )
+ )}
+ </div>
+ );
+ }}
+ />
+ );
+};
+
+const Template = (props: { item: IDropdownItem; dragHandleProps: any; commonProps: any }) => {
+ const { item, dragHandleProps, commonProps } = props;
+ const { onMouseDown, onTouchStart } = dragHandleProps;
+ const { onItemChange, onItemDelete } = commonProps;
+
+ return (
+ <div className={styles.dataValidationFormulaListItem}>
+ {!item.isRef
+ ? (
+ <div
+ className={styles.dataValidationFormulaListItemDrag}
+ onTouchStart={(e) => {
+ e.preventDefault();
+ onTouchStart(e);
+ }}
+ onMouseDown={(e) => {
+ onMouseDown(e);
+ }}
+ >
+ <SequenceSingle />
+ </div>
+ )
+ : null}
+ <ColorSelect
+ value={item.color}
+ onChange={(color) => {
+ onItemChange(item.id, item.label, color);
+ }}
+ />
+ <Input
+ disabled={item.isRef}
+ value={item.label}
+ onChange={(label) => {
+ onItemChange(item.id, label, item.color);
+ }}
+ />
+ {item.isRef
+ ? null
+ : (
+ <div className={styles.dataValidationFormulaListItemIcon}>
+ <DeleteSingle onClick={() => onItemDelete(item.id)} />
+ </div>
+ )}
+ </div>
+ );
+};
+
+export function ListFormulaInput(props: IFormulaInputProps) {
+ const { value, onChange: _onChange = () => { }, unitId, subUnitId, validResult, showError } = props;
+ const { formula1 = '', formula2 = '' } = value || {};
+ const containerRef = useRef<HTMLDivElement>(null);
+ const [isRefRange, setIsRefRange] = useState(() => isReferenceString(formula1) ? '1' : '0');
+ const [refRange, setRefRange] = useState(isRefRange === '1' ? formula1 : '');
+ const localeService = useDependency(LocaleService);
+ const univerInstanceService = useDependency(IUniverInstanceService);
+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+ const [refColors, setRefColors] = useState(() => formula2.split(','));
+
+ const formula1Res = showError ? validResult?.formula1 : '';
+
+ const onChange = useEvent(_onChange);
+
+ const [strList, setStrList] = useState<IDropdownItem[]>(() => {
+ const strOptions = isRefRange !== '1' ? deserializeListOptions(formula1) : [];
+ const strColors = formula2.split(',');
+ return strOptions.map((label, i) => ({
+ label,
+ color: strColors[i] || DROP_DOWN_DEFAULT_COLOR,
+ isRef: false,
+ id: Tools.generateRandomId(4),
+ }));
+ });
+
+ const handleStrItemChange = (id: string, value: string, color: string) => {
+ const item = strList.find((i) => i.id === id);
+ if (!item) {
+ return;
+ }
+
+ item.label = value;
+ item.color = color;
+
+ setStrList([...strList]);
+ };
+
+ const handleStrItemDelete = (id: string) => {
+ const index = strList.findIndex((i) => i.id === id);
+ if (index !== -1) {
+ strList.splice(index, 1);
+ setStrList([...strList]);
+ }
+ };
+
+ const refOptions = useMemo(() => getSheetRangeValueSet(
+ deserializeRangeWithSheet(refRange),
+ univerInstanceService,
+ workbook.getUnitId(),
+ worksheet.getSheetId()
+ ), [refRange, univerInstanceService, workbook, worksheet]);
+
+ const colorList = formula2.split(',');
+
+ const refFinalList: IDropdownItem[] = useMemo(() => refOptions.map((label, i) => ({
+ label,
+ color: colorList[i] || DROP_DOWN_DEFAULT_COLOR,
+ id: `${i}`,
+ isRef: true,
+ })), [colorList, refOptions]);
+
+ const handleRefItemChange = (id: string, value: string, color: string) => {
+ const newColors = [...refColors];
+ newColors[+id] = color;
+ setRefColors(newColors);
+
+ onChange({
+ formula1,
+ formula2: newColors.join(','),
+ });
+ };
+
+ const handleAdd = () => {
+ setStrList([
+ ...strList,
+ {
+ label: '',
+ color: DROP_DOWN_DEFAULT_COLOR,
+ isRef: false,
+ id: Tools.generateRandomId(4),
+ },
+ ]);
+ };
+
+ useEffect(() => {
+ const labelSet = new Set<string>();
+ const finalList: { color: string; label: string }[] = [];
+ strList.map((item) => {
+ const labelList = item.label.split(',');
+ return {
+ labelList,
+ item,
+ };
+ }).forEach(({ item, labelList }) => {
+ labelList.forEach((labelItem) => {
+ if (!labelSet.has(labelItem)) {
+ labelSet.add(labelItem);
+ finalList.push({
+ label: labelItem,
+ color: item.color,
+ });
+ }
+ });
+ });
+
+ onChange({
+ formula1: serializeListOptions(finalList.map((item) => item.label)),
+ formula2: finalList.map((item) => item.color === DROP_DOWN_DEFAULT_COLOR ? '' : item.color).join(','),
+ });
+ }, [strList, onChange]);
+
+ return (
+ <>
+ <FormLayout label="选项来源">
+ <RadioGroup value={isRefRange} onChange={(v) => setIsRefRange(v as string)}>
+ <Radio value="0">自定义</Radio>
+ <Radio value="1">引用数据</Radio>
+ </RadioGroup>
+ </FormLayout>
+ {isRefRange === '1' ? (
+ <>
+ <FormLayout error={formula1Res}>
+ <RangeSelector
+ id={`list-ref-range-${unitId}-${subUnitId}`}
+ value={refRange}
+ openForSheetUnitId={unitId}
+ openForSheetSubUnitId={subUnitId}
+ onChange={(ranges) => {
+ const range = ranges[0];
+ if (!range || isRangeInValid(range.range)) {
+ onChange?.({
+ formula1: '',
+ formula2,
+ });
+ setRefRange('');
+ } else {
+ const workbook = univerInstanceService.getUniverSheetInstance(range.unitId) ?? univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook?.getSheetBySheetId(range.sheetId) ?? workbook.getActiveSheet();
+ const rangeStr = serializeRangeWithSheet(worksheet.getName(), range.range);
+ onChange?.({
+ formula1: rangeStr,
+ formula2,
+ });
+ setRefRange(rangeStr);
+ }
+ }}
+ isSingleChoice
+ />
+ </FormLayout>
+ <FormLayout>
+ <div ref={containerRef}>
+ <DraggableList
+ itemKey="id"
+ // @ts-ignore
+ template={Template}
+ list={refFinalList}
+ container={() => containerRef.current}
+ commonProps={{
+ onItemChange: handleRefItemChange,
+ }}
+ />
+ </div>
+ </FormLayout>
+ </>
+ ) : (
+ <FormLayout error={formula1Res}>
+ <div ref={containerRef}>
+ <DraggableList
+ itemKey="id"
+ // @ts-ignore
+ template={Template}
+ list={strList}
+ onMoveEnd={(newList) => {
+ // @ts-ignore
+ setStrList(newList);
+ }}
+ container={() => containerRef.current}
+ commonProps={{
+ onItemChange: handleStrItemChange,
+ onItemDelete: handleStrItemDelete,
+ }}
+ />
+ <a className={styles.dataValidationFormulaListAdd} onClick={handleAdd}>
+ <IncreaseSingle />
+ {localeService.t('dataValidation.list.add')}
+ </a>
+ </div>
+ </FormLayout>
+ )}
+ </>
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/index.ts b/packages/sheets-data-validation/src/views/index.ts
new file mode 100644
index 0000000000..a9f4df9dd3
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/index.ts
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+export { DataValidationPanel } from './panel';
+export { ListDropDown } from './list-dropdown';
+export { DateDropdown } from './date-dropdown';
+export const LIST_DROPDOWN_KEY = 'data-validation.list.dropdown';
+export const DATE_DROPDOWN_KEY = 'data-validation.date.dropdown';
diff --git a/packages/sheets-data-validation/src/views/item/index.module.less b/packages/sheets-data-validation/src/views/item/index.module.less
new file mode 100644
index 0000000000..5e12154d66
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/item/index.module.less
@@ -0,0 +1,50 @@
+.data-validation-item {
+ &-container {
+ border-radius: var(--border-radius-base);
+ background-color: rgba(var(--bg-color-secondary));
+ padding: var(--padding-sm);
+ padding-right: 36px;
+ margin-left: -8px;
+ margin-right: -8px;
+ box-sizing: border-box;
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ cursor: pointer;
+ position: relative;
+ border-radius: 6px;
+ }
+
+ &-container:hover {
+ background-color: #f5f5f5;
+ }
+
+ &-title {
+ font-size: var(--font-size-sm);
+ color: rgba(var(--color-black));
+ line-height: 22px;
+ font-weight: 500;
+ }
+
+ &-content {
+ color: #7a7a7a;
+ font-size: var(--font-size-xs);
+ line-height: 18px;
+ }
+
+ &-icon {
+ position: absolute;
+ top: 19px;
+ right: 8px;
+ width: 20px;
+ height: 20px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ border-radius: 4px;
+ }
+
+ &-icon:hover {
+ background: #e5e5e5;
+ }
+}
diff --git a/packages/sheets-data-validation/src/views/item/index.tsx b/packages/sheets-data-validation/src/views/item/index.tsx
new file mode 100644
index 0000000000..4ba267bbef
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/item/index.tsx
@@ -0,0 +1,110 @@
+/**
+ * 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 { ICommandService, type ISheetDataValidationRule } from '@univerjs/core';
+import { DataValidatorRegistryService, RemoveDataValidationCommand } from '@univerjs/data-validation';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import React, { useEffect, useRef, useState } from 'react';
+import { serializeRange } from '@univerjs/engine-formula';
+import { DeleteSingle } from '@univerjs/icons';
+import { IMarkSelectionService } from '@univerjs/sheets-ui';
+import styles from './index.module.less';
+
+export interface IDataValidationDetailProps {
+ rule: ISheetDataValidationRule;
+ onClick: () => void;
+ unitId: string;
+ subUnitId: string;
+}
+
+export const DataValidationItem = (props: IDataValidationDetailProps) => {
+ const { rule, onClick, unitId, subUnitId } = props;
+ const validatorRegistry = useDependency(DataValidatorRegistryService);
+ const commandService = useDependency(ICommandService);
+ const markSelectionService = useDependency(IMarkSelectionService);
+ const validator = validatorRegistry.getValidatorItem(rule.type);
+ const ids = useRef<(string | null)[]>();
+ const [isHover, setIsHover] = useState(false);
+ const handleDelete = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
+ commandService.executeCommand(RemoveDataValidationCommand.id, {
+ ruleId: rule.uid,
+ unitId,
+ subUnitId,
+ });
+ e.stopPropagation();
+ };
+
+ useEffect(() => {
+ return () => {
+ if (ids.current) {
+ ids.current?.forEach((id) => {
+ id && markSelectionService.removeShape(id);
+ });
+ }
+ };
+ }, [markSelectionService]);
+
+ return (
+ <div
+ className={styles.dataValidationItemContainer}
+ onClick={onClick}
+ onMouseEnter={() => {
+ setIsHover(true);
+ ids.current = rule.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,
+ },
+ }));
+ }}
+ onMouseLeave={() => {
+ setIsHover(false);
+ ids.current?.forEach((id) => {
+ id && markSelectionService.removeShape(id);
+ });
+ ids.current = undefined;
+ }}
+ >
+ <div className={styles.dataValidationItemTitle}>
+ {validator?.generateRuleName(rule)}
+ </div>
+ <div className={styles.dataValidationItemContent}>
+ {rule.ranges.map((range) => serializeRange(range)).join(',')}
+ </div>
+ {isHover
+ ? (
+ <div className={styles.dataValidationItemIcon} onClick={handleDelete}>
+ <DeleteSingle />
+ </div>
+ )
+ : null}
+ </div>
+ );
+};
diff --git a/packages/sheets-data-validation/src/views/list-dropdown/index.module.less b/packages/sheets-data-validation/src/views/list-dropdown/index.module.less
new file mode 100644
index 0000000000..0b7f7b5c70
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/list-dropdown/index.module.less
@@ -0,0 +1,89 @@
+.dv-list-dropdown {
+ border-radius: 8px;
+ border: 1px solid rgba(var(--color-grey200));
+ background: rgba(var(--color-white));
+ box-shadow: var(--box-shadow-base);
+ padding: 8px;
+ max-height: 267px;
+ display: flex;
+ flex-direction: column;
+ max-width: 200px;
+
+ &-title {
+ padding: 0 6px;
+ color: var(--grey-500);
+ font-size: 12px;
+ line-height: 1.5;
+ flex-shrink: 0;
+ flex-grow: 0;
+ }
+ &-list {
+ flex: 1;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ }
+
+ &-selected-icon {
+ width: 16px;
+ height: 16px;
+ font-size: 16px;
+ color: rgba(var(--blue-500));
+ flex-shrink: 0;
+ flex-grow: 0;
+ margin-left: 12px;
+ }
+
+ &-item-container {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ justify-content: space-between;
+ padding: 4px 6px;
+ border-radius: 6px;
+ margin-top: 4px;
+ cursor: pointer;
+ }
+
+ &-item-container:hover {
+ background-color: rgba(var(--grey-50));
+ }
+
+ &-item {
+ padding: 0 4px;
+ font-size: 12px;
+ font-style: normal;
+ font-weight: 400;
+ line-height: 16px;
+ border-radius: 8px;
+ height: 16px;
+ width: fit-content;
+ flex: 0 1 auto;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ color: rgba(var(--color-black));
+ white-space: nowrap;
+ }
+
+ &-split {
+ height: 1px;
+ margin: 4px 0;
+ background: rgba(var(--grey-200));
+ flex-shrink: 0;
+ flex-grow: 0;
+ }
+
+ &-edit {
+ padding: 3px 6px;
+ margin-top: 4px;
+ font-size: 12px;
+ line-height: 1.5;
+ cursor: pointer;
+ flex-shrink: 0;
+ flex-grow: 0;
+ border-radius: 6px;
+ }
+
+ &-edit:hover {
+ background: #f5f5f5;
+ }
+}
diff --git a/packages/sheets-data-validation/src/views/list-dropdown/index.tsx b/packages/sheets-data-validation/src/views/list-dropdown/index.tsx
new file mode 100644
index 0000000000..c3de18fdf8
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/list-dropdown/index.tsx
@@ -0,0 +1,166 @@
+/**
+ * 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 { DataValidationType, ICommandService, LocaleService } from '@univerjs/core';
+import type { ISetRangeValuesCommandParams } from '@univerjs/sheets';
+import { SetRangeValuesCommand } from '@univerjs/sheets';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import React, { useState } from 'react';
+import { CheckMarkSingle } from '@univerjs/icons';
+import { IEditorBridgeService } from '@univerjs/sheets-ui';
+import { KeyCode } from '@univerjs/ui';
+import { DeviceInputEventType } from '@univerjs/engine-render';
+import { DataValidationRenderMode } from '@univerjs/core/types/enum/data-validation-render-mode.js';
+import type { ListMultipleValidator } from '../../validators/list-multiple-validator';
+import { deserializeListOptions, getDataValidationCellValue, serializeListOptions } from '../../validators/util';
+import type { IDropdownComponentProps } from '../../services/dropdown-manager.service';
+import { DROP_DOWN_DEFAULT_COLOR } from '../../common/const';
+import { OpenValidationPanelOperation } from '../../commands/operations/data-validation.operation';
+import styles from './index.module.less';
+
+interface ISelectListProps {
+ value: string[];
+ onChange: (val: string[]) => void;
+ multiple?: boolean;
+ options: { label: string;value: string; color?: string }[];
+ title?: string;
+ onEdit?: () => void;
+}
+
+const SelectList = (props: ISelectListProps) => {
+ const { value, onChange, multiple, options, title, onEdit } = props;
+ return (
+ <div className={styles.dvListDropdown}>
+ <div className={styles.dvListDropdownTitle}>
+ {title}
+ </div>
+ <div className={styles.dvListDropdownList}>
+ {options.map((item, i) => {
+ const selected = value.indexOf(item.value) > -1;
+ const handleClick = () => {
+ let set: Set<string>;
+ if (selected) {
+ set = new Set(value.filter((sub) => sub !== item.value));
+ } else {
+ set = new Set(multiple ? [...value, item.value] : [item.value]);
+ }
+ const newValue: string[] = [];
+ options.forEach((opt) => {
+ if (set.has(opt.value)) {
+ newValue.push(opt.value);
+ }
+ });
+
+ onChange(newValue);
+ };
+ return (
+ <div key={i} className={styles.dvListDropdownItemContainer} onClick={handleClick}>
+ <div className={styles.dvListDropdownItem} style={{ background: item.color || DROP_DOWN_DEFAULT_COLOR }}>{item.label}</div>
+ <div className={styles.dvListDropdownSelectedIcon}>
+ {selected ? <CheckMarkSingle /> : null}
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ <div className={styles.dvListDropdownSplit} />
+ <div className={styles.dvListDropdownEdit} onClick={onEdit}>
+ 编辑
+ </div>
+ </div>
+ );
+};
+
+export function ListDropDown(props: IDropdownComponentProps) {
+ const { location, hideFn } = props;
+ const { worksheet, row, col, unitId, subUnitId } = location;
+ const commandService = useDependency(ICommandService);
+ const localeService = useDependency(LocaleService);
+ const [localValue, setLocalValue] = useState('');
+ const editorBridgeService = useDependency(IEditorBridgeService);
+
+ if (!worksheet) {
+ return null;
+ }
+
+ const cellData = worksheet.getCell(row, col);
+ const rule = cellData?.dataValidation?.rule;
+ const validator = cellData?.dataValidation?.validator as ListMultipleValidator | undefined;
+ const showColor = rule?.renderMode === DataValidationRenderMode.CUSTOM || rule?.renderMode === undefined;
+
+ if (!cellData || !rule || !validator) {
+ return;
+ }
+
+ const multiple = rule.type === DataValidationType.LIST_MULTIPLE;
+ const list = validator.getListWithColor(rule, unitId, subUnitId);
+ const cellStr = localValue || getDataValidationCellValue(cellData);
+ const value = deserializeListOptions(cellStr);
+
+ const handleEdit = () => {
+ commandService.executeCommand(OpenValidationPanelOperation.id, {
+ ruleId: rule.uid,
+ });
+ hideFn();
+ };
+
+ return (
+ <SelectList
+ title={multiple ? localeService.t('dataValidation.listMultiple.dropdown') : localeService.t('dataValidation.list.dropdown')}
+ value={value}
+ multiple={multiple}
+ onChange={(newValue) => {
+ const str = serializeListOptions(newValue);
+ const params: ISetRangeValuesCommandParams = {
+ unitId,
+ subUnitId,
+ range: {
+ startColumn: col,
+ endColumn: col,
+ startRow: row,
+ endRow: row,
+ },
+ value: {
+ v: str,
+ p: null,
+ f: null,
+ si: null,
+ },
+ };
+
+ if (editorBridgeService.isVisible()) {
+ editorBridgeService.changeVisible({
+ visible: false,
+ keycode: KeyCode.ESC,
+ eventType: DeviceInputEventType.Keyboard,
+ });
+ }
+
+ commandService.executeCommand(SetRangeValuesCommand.id, params);
+ setLocalValue(str);
+ if (!multiple) {
+ hideFn();
+ }
+ }}
+ options={list.map((item) => ({
+ label: item.label,
+ value: item.label,
+ color: showColor ? item.color : 'transparent',
+ }))}
+ onEdit={handleEdit}
+ />
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/list/index.module.less b/packages/sheets-data-validation/src/views/list/index.module.less
new file mode 100644
index 0000000000..bd63f402d3
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/list/index.module.less
@@ -0,0 +1,12 @@
+.data-validation-list {
+ &-buttons {
+ margin-top: 20px;
+ display: flex;
+ flex-direction: row;
+ justify-content: flex-end;
+ }
+
+ &-button {
+ margin-left: 12px;
+ }
+}
diff --git a/packages/sheets-data-validation/src/views/list/index.tsx b/packages/sheets-data-validation/src/views/list/index.tsx
new file mode 100644
index 0000000000..ff7fa05967
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/list/index.tsx
@@ -0,0 +1,108 @@
+/**
+ * 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 React, { memo, useEffect, useState } from 'react';
+import { Injector } from '@wendellhu/redi';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import type { ISheetDataValidationRule } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';
+import { createDefaultNewRule, DataValidationModel, RemoveAllDataValidationCommand } from '@univerjs/data-validation';
+import { Button } from '@univerjs/design';
+import { useObservable } from '@univerjs/ui';
+import { DataValidationItem } from '../item';
+import type { IAddSheetDataValidationCommandParams } from '../../commands/commands/data-validation.command';
+import { AddSheetDataValidationCommand } from '../../commands/commands/data-validation.command';
+import { DataValidationPanelService } from '../../services/data-validation-panel.service';
+import styles from './index.module.less';
+
+export const DataValidationList = memo(() => {
+ const univerInstanceService = useDependency(IUniverInstanceService);
+ const dataValidationModel = useDependency(DataValidationModel);
+ const commandService = useDependency(ICommandService);
+ const injector = useDependency(Injector);
+ const dataValidationPanelService = useDependency(DataValidationPanelService);
+ const workbook = useObservable(univerInstanceService.currentSheet$, univerInstanceService.getCurrentUniverSheetInstance()) ?? univerInstanceService.getCurrentUniverSheetInstance();
+ const localeService = useDependency(LocaleService);
+ const [rules, setRules] = useState<ISheetDataValidationRule[]>([]);
+ const worksheet = useObservable(workbook.activeSheet$, workbook.getActiveSheet()) ?? workbook.getActiveSheet();
+ const unitId = workbook.getUnitId();
+ const subUnitId = worksheet.getSheetId();
+ const manager = dataValidationModel.ensureManager(unitId, subUnitId);
+
+ useEffect(() => {
+ setRules(manager.getDataValidations());
+
+ const subscription = manager.dataValidations$.subscribe((currentRules) => {
+ setRules([...currentRules]);
+ });
+
+ return () => {
+ subscription.unsubscribe();
+ };
+ }, [manager]);
+
+ const handleAddRule = async () => {
+ const rule = createDefaultNewRule(injector);
+ const params: IAddSheetDataValidationCommandParams = {
+ unitId,
+ subUnitId,
+ rule,
+ };
+ await commandService.executeCommand(AddSheetDataValidationCommand.id, params);
+ dataValidationPanelService.setActiveRule({
+ unitId,
+ subUnitId,
+ rule,
+ });
+ };
+
+ const handleRemoveAll = () => {
+ commandService.executeCommand(RemoveAllDataValidationCommand.id, {
+ unitId,
+ subUnitId,
+ });
+ };
+
+ return (
+ <div>
+ {rules.map((rule) => (
+ <DataValidationItem
+ unitId={unitId}
+ subUnitId={subUnitId}
+ onClick={() => dataValidationPanelService.setActiveRule({
+ unitId,
+ subUnitId,
+ rule,
+ })}
+ rule={rule}
+ key={rule.uid}
+ />
+ ))}
+ <div className={styles.dataValidationListButtons}>
+ {rules.length
+ ? (
+ <Button className={styles.dataValidationListButton} onClick={handleRemoveAll}>
+ {localeService.t('dataValidation.panel.removeAll')}
+ </Button>
+ )
+ : null}
+ <Button className={styles.dataValidationListButton} type="primary" onClick={handleAddRule}>
+ {localeService.t('dataValidation.panel.add')}
+ </Button>
+ </div>
+ </div>
+ );
+});
diff --git a/packages/sheets-data-validation/src/views/options/index.module.less b/packages/sheets-data-validation/src/views/options/index.module.less
new file mode 100644
index 0000000000..164fa7034f
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/options/index.module.less
@@ -0,0 +1,15 @@
+.data-validation-options {
+ &-button {
+ cursor: pointer;
+ margin-bottom: 12px;
+ font-size: var(--font-size-sm);
+ color: rgba(var(--color-black));
+ display: flex;
+ align-items: center;
+
+ &-icon {
+ font-size: 8px;
+ margin-left: 4px;
+ }
+ }
+}
diff --git a/packages/sheets-data-validation/src/views/options/index.tsx b/packages/sheets-data-validation/src/views/options/index.tsx
new file mode 100644
index 0000000000..cddf0c7252
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/options/index.tsx
@@ -0,0 +1,87 @@
+/**
+ * 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 { DataValidationErrorStyle, type IDataValidationRuleOptions, LocaleService } from '@univerjs/core';
+import { Checkbox, FormLayout, Input, Radio, RadioGroup } from '@univerjs/design';
+import React, { useState } from 'react';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { MoreDownSingle, MoreUpSingle } from '@univerjs/icons';
+import { ComponentManager } from '@univerjs/ui';
+import styles from './index.module.less';
+
+export interface IDataValidationOptionsParams {
+ value: IDataValidationRuleOptions;
+ onChange: (value: IDataValidationRuleOptions) => void;
+ extraComponent?: string;
+}
+
+export function DataValidationOptions(props: IDataValidationOptionsParams) {
+ const localeService = useDependency(LocaleService);
+ const componentManager = useDependency(ComponentManager);
+ const { value, onChange, extraComponent } = props;
+ const [show, setShow] = useState(false);
+
+ const ExtraOptions = extraComponent ? componentManager.get(extraComponent) : null;
+
+ return (
+ <>
+ <div className={styles.dataValidationOptionsButton} onClick={() => setShow(!show)}>
+ {localeService.t('dataValidation.panel.options')}
+ {show ? <MoreUpSingle className={styles.dataValidationOptionsButtonIcon} /> : <MoreDownSingle className={styles.dataValidationOptionsButtonIcon} />}
+ </div>
+ {show && (
+ <>
+ {ExtraOptions ? <ExtraOptions value={value} onChange={onChange} /> : null}
+ <FormLayout
+ label={localeService.t('dataValidation.panel.invalid')}
+ >
+ <RadioGroup
+ value={`${value.errorStyle ?? DataValidationErrorStyle.WARNING}`}
+ onChange={(errorStyle) => onChange({ ...value, errorStyle: +errorStyle })}
+ >
+ <Radio value={`${DataValidationErrorStyle.WARNING}`}>
+ {localeService.t('dataValidation.panel.showWarning')}
+ </Radio>
+ <Radio value={`${DataValidationErrorStyle.STOP}`}>
+ {localeService.t('dataValidation.panel.rejectInput')}
+ </Radio>
+ </RadioGroup>
+ </FormLayout>
+ <FormLayout
+ label={localeService.t('dataValidation.panel.messageInfo')}
+ >
+ <Checkbox
+ checked={value.showInputMessage}
+ onChange={() => onChange({
+ ...value,
+ showInputMessage: !value.showInputMessage,
+ })}
+ >
+ {localeService.t('dataValidation.panel.showInfo')}
+ </Checkbox>
+ </FormLayout>
+ {value.showInputMessage
+ ? (
+ <FormLayout>
+ <Input value={value.error} onChange={(error) => onChange({ ...value, error })} />
+ </FormLayout>
+ )
+ : null}
+ </>
+ )}
+ </>
+ );
+}
diff --git a/packages/sheets-data-validation/src/views/panel/index.tsx b/packages/sheets-data-validation/src/views/panel/index.tsx
new file mode 100644
index 0000000000..be36f41b38
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/panel/index.tsx
@@ -0,0 +1,33 @@
+/**
+ * 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 React from 'react';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { useObservable } from '@univerjs/ui';
+import { DataValidationDetail } from '../detail';
+import { DataValidationList } from '../list';
+import { DataValidationPanelService } from '../../services/data-validation-panel.service';
+
+export const DataValidationPanel = () => {
+ const dataValidationPanelService = useDependency(DataValidationPanelService);
+ const activeRule = useObservable(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule);
+
+ return (
+ activeRule
+ ? <DataValidationDetail key={activeRule.rule.uid} />
+ : <DataValidationList />
+ );
+};
diff --git a/packages/sheets-data-validation/src/views/render-mode/index.tsx b/packages/sheets-data-validation/src/views/render-mode/index.tsx
new file mode 100644
index 0000000000..0530889a26
--- /dev/null
+++ b/packages/sheets-data-validation/src/views/render-mode/index.tsx
@@ -0,0 +1,50 @@
+/**
+ * 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 { type IDataValidationRuleOptions, LocaleService } from '@univerjs/core';
+import { DataValidationRenderMode } from '@univerjs/core/types/enum/data-validation-render-mode.js';
+import { FormLayout, Radio, RadioGroup } from '@univerjs/design';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import React from 'react';
+
+export interface IListRenderModeInputProps {
+ value: IDataValidationRuleOptions;
+ onChange: (value: IDataValidationRuleOptions) => void;
+}
+const LIST_RENDER_MODE_OPTION_INPUT = 'LIST_RENDER_MODE_OPTION_INPUT';
+
+export function ListRenderModeInput(props: IListRenderModeInputProps) {
+ const { value, onChange } = props;
+ const localeService = useDependency(LocaleService);
+
+ return (
+ <FormLayout label={localeService.t('dataValidation.renderMode.label')}>
+ <RadioGroup value={`${value.renderMode ?? DataValidationRenderMode.CUSTOM}`} onChange={(renderMode) => onChange({ ...value, renderMode: +renderMode })}>
+ <Radio value={`${DataValidationRenderMode.CUSTOM}`}>
+ {localeService.t('dataValidation.renderMode.chip')}
+ </Radio>
+ <Radio value={`${DataValidationRenderMode.ARROW}`}>
+ {localeService.t('dataValidation.renderMode.arrow')}
+ </Radio>
+ <Radio value={`${DataValidationRenderMode.TEXT}`}>
+ {localeService.t('dataValidation.renderMode.text')}
+ </Radio>
+ </RadioGroup>
+ </FormLayout>
+ );
+}
+
+ListRenderModeInput.componentKey = LIST_RENDER_MODE_OPTION_INPUT;
diff --git a/packages/sheets-data-validation/src/vite-env.d.ts b/packages/sheets-data-validation/src/vite-env.d.ts
new file mode 100644
index 0000000000..11f02fe2a0
--- /dev/null
+++ b/packages/sheets-data-validation/src/vite-env.d.ts
@@ -0,0 +1 @@
+/// <reference types="vite/client" />
diff --git a/packages/sheets-data-validation/src/widgets/checkbox-widget.ts b/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
new file mode 100644
index 0000000000..18d0e008a7
--- /dev/null
+++ b/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
@@ -0,0 +1,201 @@
+/**
+ * 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 type { IMouseEvent, IPointerEvent, UniverRenderingContext2D } from '@univerjs/engine-render';
+import { Checkbox, fixLineWidthByScale, Transform } from '@univerjs/engine-render';
+import { HorizontalAlign, ICommandService, isFormulaString, ThemeService, VerticalAlign } from '@univerjs/core';
+import type { ICellRenderContext, IDataValidationRule, IStyleData, Nullable } from '@univerjs/core';
+import type { ISetRangeValuesCommandParams } from '@univerjs/sheets';
+import { SetRangeValuesCommand } from '@univerjs/sheets';
+import type { BaseDataValidator, IBaseDataValidationWidget, IFormulaResult } from '@univerjs/data-validation';
+import { Inject } from '@wendellhu/redi';
+import { CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2 } from '../validators/checkbox-validator';
+import { DataValidationFormulaService } from '../services/dv-formula.service';
+import { getFormulaResult } from '../utils/formula';
+import { getCellValueOrigin } from '../utils/get-cell-data-origin';
+
+const MARGIN_H = 6;
+
+export class CheckboxRender implements IBaseDataValidationWidget {
+ private _calc(cellInfo: { startX: number; endX: number; startY: number;endY: number }, style: Nullable<IStyleData>) {
+ const { vt, ht } = style || {};
+ const width = cellInfo.endX - cellInfo.startX - (MARGIN_H * 2);
+ const height = cellInfo.endY - cellInfo.startY;
+ const size = (style?.fs ?? 10) * 1.6;
+ let widgetLeft = 0;
+ let widgetTop = 0;
+ switch (vt) {
+ case VerticalAlign.TOP:
+ widgetTop = 0;
+ break;
+ case VerticalAlign.BOTTOM:
+ widgetTop = 0 + (height - size);
+ break;
+ default:
+ widgetTop = 0 + (height - size) / 2;
+ break;
+ }
+
+ switch (ht) {
+ case HorizontalAlign.LEFT:
+ widgetLeft = MARGIN_H;
+ break;
+ case HorizontalAlign.RIGHT:
+ widgetLeft = MARGIN_H + (width - size);
+ break;
+
+ default:
+ widgetLeft = MARGIN_H + (width - size) / 2;
+ break;
+ }
+
+ return {
+ left: cellInfo.startX + widgetLeft,
+ top: cellInfo.startY + widgetTop,
+ width: (style?.fs ?? 10) * 1.6,
+ height: (style?.fs ?? 10) * 1.6,
+ };
+ }
+
+ constructor(
+ @ICommandService private readonly _commandService: ICommandService,
+ @Inject(DataValidationFormulaService) private readonly _formulaService: DataValidationFormulaService,
+ @Inject(ThemeService) private readonly _themeService: ThemeService
+ ) {}
+
+ calcCellAutoHeight(): number | undefined {
+ return undefined;
+ }
+
+ private async _parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult> {
+ const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule;
+ const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
+ return {
+ formula1: isFormulaString(formula1) ? getFormulaResult(results?.[0]?.result) : formula1,
+ formula2: isFormulaString(formula2) ? getFormulaResult(results?.[1]?.result) : formula2,
+ };
+ }
+
+ drawWith(ctx: UniverRenderingContext2D, info: ICellRenderContext): void {
+ const { style, data, primaryWithCoord, unitId, subUnitId } = info;
+ const cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
+ const value = getCellValueOrigin(data);
+ const rule = data.dataValidation?.rule;
+ const validator = data.dataValidation?.validator as BaseDataValidator;
+ if (!rule || !validator) {
+ return;
+ }
+
+ const colors = this._themeService.getCurrentTheme();
+ if (!validator.skipDefaultFontRender(rule, value, { unitId, subUnitId })) {
+ return;
+ }
+
+ const { formula1 = CHECKBOX_FORMULA_1 } = rule;
+
+ const layout = this._calc(cellBounding, style);
+ const { a: scaleX, d: scaleY } = ctx.getTransform();
+ const left = fixLineWidthByScale(layout.left, scaleX);
+ const top = fixLineWidthByScale(layout.top, scaleY);
+
+ const transform = Transform.create().composeMatrix({
+ left,
+ top,
+ scaleX: 1,
+ scaleY: 1,
+ angle: 0,
+ skewX: 0,
+ skewY: 0,
+ flipX: false,
+ flipY: false,
+ });
+
+ const cellWidth = cellBounding.endX - cellBounding.startX;
+ const cellHeight = cellBounding.endY - cellBounding.startY;
+
+ ctx.save();
+ ctx.beginPath();
+ ctx.rect(cellBounding.startX, cellBounding.startY, cellWidth, cellHeight);
+ ctx.clip();
+
+ const m = transform.getMatrix();
+ ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
+ const size = (style?.fs ?? 10) * 1.6;
+
+ const checked = String(value) === String(formula1);
+ const defaultColor = colors.hyacinth500;
+
+ Checkbox.drawWith(ctx, {
+ checked,
+ width: size,
+ height: size,
+ fill: style?.cl?.rgb ?? defaultColor,
+ });
+
+ ctx.restore();
+ }
+
+ isHit(evt: { x: number;y: number }, info: ICellRenderContext): boolean {
+ const cellBounding = info.primaryWithCoord.isMergedMainCell ? info.primaryWithCoord.mergeInfo : info.primaryWithCoord;
+ const layout = this._calc(cellBounding, info.style);
+ const startY = layout.top;
+ const endY = layout.top + layout.height;
+ const startX = layout.left;
+ const endX = layout.left + layout.width;
+ const { x: offsetX, y: offsetY } = evt;
+ if (offsetX <= endX && offsetX >= startX && offsetY <= endY && offsetY >= startY) {
+ return true;
+ }
+
+ return false;
+ }
+
+ async onPointerDown(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ if (evt.button === 2) {
+ return;
+ }
+ const { primaryWithCoord, unitId, subUnitId, data } = info;
+ const value = getCellValueOrigin(data);
+ const rule = data.dataValidation?.rule;
+ const validator = data.dataValidation?.validator as BaseDataValidator;
+ if (!rule || !validator) {
+ return;
+ }
+
+ if (!validator.skipDefaultFontRender(rule, value, { unitId, subUnitId })) {
+ return;
+ }
+
+ const { formula1, formula2 } = await this._parseFormula(rule, unitId!, subUnitId);
+ const params: ISetRangeValuesCommandParams = {
+ range: {
+ startColumn: primaryWithCoord.actualColumn,
+ endColumn: primaryWithCoord.actualColumn,
+ startRow: primaryWithCoord.actualRow,
+ endRow: primaryWithCoord.actualRow,
+ },
+ value: {
+ v: String(value) === String(formula1) ? formula2 : formula1,
+ p: null,
+ },
+ };
+
+ this._commandService.executeCommand(
+ SetRangeValuesCommand.id,
+ params
+ );
+ };
+}
diff --git a/packages/sheets-data-validation/src/widgets/dropdown-multiple-widget.ts b/packages/sheets-data-validation/src/widgets/dropdown-multiple-widget.ts
new file mode 100644
index 0000000000..e86f194eaa
--- /dev/null
+++ b/packages/sheets-data-validation/src/widgets/dropdown-multiple-widget.ts
@@ -0,0 +1,201 @@
+/**
+ * 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 { HorizontalAlign, ICommandService, VerticalAlign } from '@univerjs/core';
+import type { ICellRenderContext } from '@univerjs/core';
+import { getFontStyleString, type IMouseEvent, type IPointerEvent, type Spreadsheet, type SpreadsheetSkeleton, type UniverRenderingContext2D } from '@univerjs/engine-render';
+import type { IBaseDataValidationWidget } from '@univerjs/data-validation';
+import type { ListMultipleValidator } from '../validators/list-multiple-validator';
+import { getCellValueOrigin } from '../utils/get-cell-data-origin';
+import type { IShowDataValidationDropdownParams } from '../commands/operations/data-validation.operation';
+import { ShowDataValidationDropdown } from '../commands/operations/data-validation.operation';
+import type { IDropdownInfo } from './dropdown-widget';
+import { CELL_PADDING_H, CELL_PADDING_V, Dropdown, ICON_PLACE, layoutDropdowns, MARGIN_V } from './shape';
+
+const downPath = new Path2D('M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z');
+
+export class DropdownMultipleWidget implements IBaseDataValidationWidget {
+ zIndex?: number | undefined;
+ private _dropdownInfoMap: Map<string, Map<string, IDropdownInfo>> = new Map();
+
+ constructor(
+ @ICommandService private readonly _commandService: ICommandService
+ ) {}
+
+ private _ensureMap(subUnitId: string) {
+ let map = this._dropdownInfoMap.get(subUnitId);
+
+ if (!map) {
+ map = new Map();
+ this._dropdownInfoMap.set(subUnitId, map);
+ }
+ return map;
+ }
+
+ private _generateKey(row: number, col: number) {
+ return `${row}.${col}`;
+ }
+
+ private _drawDownIcon(ctx: UniverRenderingContext2D, cellBounding: { startX: number;startY: number }, cellWidth: number, cellHeight: number, vt: VerticalAlign) {
+ const left = cellWidth - ICON_PLACE + 4;
+ let top = 4;
+
+ switch (vt) {
+ case VerticalAlign.MIDDLE:
+ top = (cellHeight - ICON_PLACE) / 2 + 4;
+ break;
+ case VerticalAlign.BOTTOM:
+ top = (cellHeight - ICON_PLACE) + 4;
+ break;
+ default:
+ break;
+ }
+
+ ctx.save();
+ ctx.translateWithPrecision(cellBounding.startX + left, cellBounding.startY + top);
+ ctx.fillStyle = '#565656';
+ ctx.fill(downPath);
+ ctx.restore();
+ }
+
+ drawWith(ctx: UniverRenderingContext2D, info: ICellRenderContext, skeleton: SpreadsheetSkeleton, spreadsheets: Spreadsheet): void {
+ const { primaryWithCoord, row, col, style, data, subUnitId } = info;
+ const cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
+ const validation = data.dataValidation;
+ const cellWidth = cellBounding.endX - cellBounding.startX;
+ const cellHeight = cellBounding.endY - cellBounding.startY;
+
+ const map = this._ensureMap(subUnitId);
+ const key = this._generateKey(row, col);
+
+ if (!validation) {
+ return;
+ }
+ const { cl } = style || {};
+ const color = (typeof cl === 'object' ? cl?.rgb : cl) ?? '#000';
+ const fontStyle = getFontStyleString(style ?? undefined);
+ const { rule, validator: _validator } = validation;
+ const validator = _validator as ListMultipleValidator;
+ const { vt: _vt, ht } = style || {};
+ const vt = _vt ?? VerticalAlign.MIDDLE;
+ const cellValue = getCellValueOrigin(data) ?? '';
+ const items = validator.parseCellValue(cellValue, rule);
+ const labelColorMap = validator.getListWithColorMap(rule);
+ const layout = layoutDropdowns(items, fontStyle, cellWidth, cellHeight);
+ this._drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, vt);
+ ctx.save();
+ ctx.translateWithPrecision(cellBounding.startX, cellBounding.startY);
+ ctx.beginPath();
+ ctx.rect(0, 0, cellWidth - ICON_PLACE, cellHeight);
+ ctx.clip();
+ ctx.translateWithPrecision(CELL_PADDING_H, CELL_PADDING_V);
+ let top = 0;
+ switch (vt) {
+ case VerticalAlign.MIDDLE:
+ top = (layout.contentHeight - layout.totalHeight) / 2;
+ break;
+ case VerticalAlign.BOTTOM:
+ top = (layout.contentHeight - layout.totalHeight);
+ break;
+ default:
+ break;
+ }
+ ctx.translateWithPrecision(0, top);
+ layout.lines.forEach((line, index) => {
+ ctx.save();
+ const { width, height, items } = line;
+ let left = 0;
+ switch (ht) {
+ case HorizontalAlign.RIGHT:
+ left = layout.contentWidth - width;
+ break;
+ case HorizontalAlign.CENTER:
+ left = (layout.contentWidth - width) / 2;
+ break;
+ default:
+ break;
+ }
+ ctx.translate(left, index * (height + MARGIN_V));
+ items.forEach((item) => {
+ ctx.save();
+ ctx.translateWithPrecision(item.left, 0);
+ Dropdown.drawWith(ctx, {
+ ...fontStyle,
+ info: item,
+ color,
+ fill: labelColorMap[item.text],
+ });
+ ctx.restore();
+ });
+
+ ctx.restore();
+ });
+
+ ctx.restore();
+
+ map.set(key, {
+ left: cellBounding.startX,
+ top: cellBounding.startY,
+ width: layout.contentWidth + CELL_PADDING_H + ICON_PLACE,
+ height: layout.contentHeight + CELL_PADDING_V * 2,
+ });
+ }
+
+ calcCellAutoHeight(info: ICellRenderContext): number | undefined {
+ const { primaryWithCoord, style, data } = info;
+ const cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
+ const validation = data.dataValidation;
+ if (!validation) {
+ return undefined;
+ }
+ const cellWidth = cellBounding.endX - cellBounding.startX;
+ const cellHeight = cellBounding.endY - cellBounding.startY;
+ const cellValue = getCellValueOrigin(data) ?? '';
+ const { rule, validator: _validator } = validation;
+ const validator = _validator as ListMultipleValidator;
+ const items = validator.parseCellValue(cellValue, rule);
+ const fontStyle = getFontStyleString(style ?? undefined);
+ const layout = layoutDropdowns(items, fontStyle, cellWidth, cellHeight);
+ return layout.cellAutoHeight;
+ }
+
+ isHit(position: { x: number; y: number }, info: ICellRenderContext) {
+ const { primaryWithCoord } = info;
+ const cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
+ const { endX } = cellBounding;
+ const { x } = position;
+ if (x >= endX - ICON_PLACE && x <= endX) {
+ return true;
+ }
+ return false;
+ };
+
+ onPointerDown(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ if (evt.button === 2) {
+ return;
+ }
+ const { unitId, subUnitId, row, col } = info;
+
+ const params: IShowDataValidationDropdownParams = {
+ unitId: unitId!,
+ subUnitId,
+ row,
+ column: col,
+ };
+
+ this._commandService.executeCommand(ShowDataValidationDropdown.id, params);
+ }
+}
diff --git a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
new file mode 100644
index 0000000000..a8356d2f4f
--- /dev/null
+++ b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
@@ -0,0 +1,442 @@
+/**
+ * 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 { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentDataModel, HorizontalAlign, ICommandService, LocaleService, Tools, VerticalAlign, WrapStrategy } from '@univerjs/core';
+import type { ICellRenderContext, IDocumentData, IPaddingData, IStyleData, Nullable } from '@univerjs/core';
+import { Documents, DocumentSkeleton, DocumentViewModel, getDocsSkeletonPageSize, type IMouseEvent, type IPointerEvent, Rect, type Spreadsheet, type SpreadsheetSkeleton, type UniverRenderingContext2D } from '@univerjs/engine-render';
+import { Inject } from '@wendellhu/redi';
+import { DataValidationModel, DataValidatorRegistryService, type IBaseDataValidationWidget } from '@univerjs/data-validation';
+import { DataValidationRenderMode } from '@univerjs/core/types/enum/data-validation-render-mode.js';
+import { getCellValueOrigin } from '../utils/get-cell-data-origin';
+import { type IShowDataValidationDropdownParams, ShowDataValidationDropdown } from '../commands/operations/data-validation.operation';
+import { DROP_DOWN_DEFAULT_COLOR } from '../common/const';
+import type { ListValidator } from '../validators';
+
+const PADDING_H = 4;
+const ICON_SIZE = 6;
+const ICON_PLACE = 14;
+const MARGIN_H = 6;
+const MARGIN_V = 2;
+const DROP_DOWN_ICON_COLOR = '#565656';
+
+const downPath = new Path2D('M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z');
+
+function convertToDocumentData(text: string, style?: Nullable<IStyleData>) {
+ const contentLength = text.length;
+ const documentData: IDocumentData = {
+ id: 'd',
+ body: {
+ dataStream: `${text}${DEFAULT_EMPTY_DOCUMENT_VALUE}`,
+ textRuns: [
+ {
+ ts: {
+ fs: 11,
+ ff: undefined,
+ it: BooleanNumber.FALSE,
+ bl: BooleanNumber.FALSE,
+ ul: {
+ s: BooleanNumber.FALSE,
+ },
+ st: {
+ s: BooleanNumber.FALSE,
+ },
+ ol: {
+ s: BooleanNumber.FALSE,
+ },
+ cl: undefined,
+ ...style,
+ bg: undefined,
+ bd: undefined,
+ },
+ st: 0,
+ ed: contentLength,
+ },
+ ],
+ },
+ documentStyle: {
+ pageSize: {
+ width: Number.POSITIVE_INFINITY,
+ height: Number.POSITIVE_INFINITY,
+ },
+ },
+ };
+
+ return documentData;
+}
+
+function createDocSkeleton(text: string, localeService: LocaleService, style?: Nullable<IStyleData>) {
+ const documentData = convertToDocumentData(text, style);
+
+ const docModel = new DocumentDataModel(documentData);
+ const docViewModel = new DocumentViewModel(docModel);
+
+ const documentSkeleton = DocumentSkeleton.create(docViewModel, localeService);
+
+ return {
+ documentSkeleton,
+ docModel,
+ docViewModel,
+ };
+}
+
+function createDocuments(text: string, localeService: LocaleService, style?: Nullable<IStyleData>) {
+ const {
+ documentSkeleton,
+ docModel,
+ docViewModel,
+ } = createDocSkeleton(text, localeService, style);
+
+ const documents = new Documents(`DOCUMENTS_${Tools.generateRandomId()}`, documentSkeleton, {
+ pageMarginLeft: 0,
+ pageMarginTop: 0,
+ });
+ return {
+ documents,
+ documentSkeleton,
+ docModel,
+ docViewModel,
+ };
+}
+
+export interface IDropdownInfo {
+ top: number;
+ left: number;
+ width: number;
+ height: number;
+}
+
+export class DropdownWidget implements IBaseDataValidationWidget {
+ static padding: IPaddingData = {
+ l: MARGIN_H + PADDING_H,
+ r: ICON_PLACE + MARGIN_H,
+ t: MARGIN_V,
+ b: MARGIN_V,
+ };
+
+ private _dropdownInfoMap: Map<string, Map<string, IDropdownInfo>> = new Map();
+ constructor(
+ @Inject(LocaleService) private readonly _localeService: LocaleService,
+ @ICommandService private readonly _commandService: ICommandService,
+ @Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
+ @Inject(DataValidatorRegistryService) private readonly _dataValidatorRegistryService: DataValidatorRegistryService
+ ) { }
+
+ zIndex?: number | undefined;
+ onPointerEnter?: ((info: ICellRenderContext) => void) | undefined;
+ onPointerLeave?: ((info: ICellRenderContext) => void) | undefined;
+
+ private _ensureMap(subUnitId: string) {
+ let map = this._dropdownInfoMap.get(subUnitId);
+
+ if (!map) {
+ map = new Map();
+ this._dropdownInfoMap.set(subUnitId, map);
+ }
+ return map;
+ }
+
+ private _generateKey(row: number, col: number) {
+ return `${row}.${col}`;
+ }
+
+ private _drawDownIcon(ctx: UniverRenderingContext2D, cellBounding: { startX: number;startY: number }, cellWidth: number, cellHeight: number, vt: VerticalAlign) {
+ const left = cellWidth - ICON_PLACE + 4;
+ let top = 4;
+
+ switch (vt) {
+ case VerticalAlign.MIDDLE:
+ top = (cellHeight - ICON_PLACE) / 2 + 4;
+ break;
+ case VerticalAlign.BOTTOM:
+ top = (cellHeight - ICON_PLACE) + 4;
+ break;
+ default:
+ break;
+ }
+
+ ctx.save();
+ ctx.translateWithPrecision(cellBounding.startX + left, cellBounding.startY + top);
+ ctx.fillStyle = '#565656';
+ ctx.fill(downPath);
+ ctx.restore();
+ }
+
+ drawWith(ctx: UniverRenderingContext2D, info: ICellRenderContext, skeleton: SpreadsheetSkeleton, spreadsheets: Spreadsheet): void {
+ const { primaryWithCoord, row, col, style, data, subUnitId } = info;
+ const cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
+ const cellWidth = cellBounding.endX - cellBounding.startX;
+ const cellHeight = cellBounding.endY - cellBounding.startY;
+ const map = this._ensureMap(subUnitId);
+ const key = this._generateKey(row, col);
+
+ const rule = data.dataValidation?.rule;
+ const validator = data.dataValidation?.validator as ListValidator;
+
+ if (!rule || !validator) {
+ return;
+ }
+
+ if (!validator.skipDefaultFontRender(rule)) {
+ return;
+ }
+
+ const list = validator.getListWithColor(rule);
+ const value = getCellValueOrigin(data);
+ const valueStr = `${value ?? ''}`;
+ const activeItem = list.find((i) => i.label === valueStr);
+ let { tb, vt, ht } = style || {};
+
+ tb = tb ?? WrapStrategy.WRAP;
+ vt = vt ?? VerticalAlign.TOP;
+ ht = ht ?? HorizontalAlign.LEFT;
+ if (rule.renderMode === DataValidationRenderMode.ARROW) {
+ this._drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, vt);
+ ctx.save();
+ ctx.translateWithPrecision(cellBounding.startX, cellBounding.startY);
+ ctx.beginPath();
+ ctx.rect(0, 0, cellWidth, cellHeight);
+ ctx.clip();
+
+ const realWidth = cellWidth - ICON_PLACE;
+ const { documentSkeleton, documents, docModel } = createDocuments(valueStr, this._localeService, style);
+
+ if (
+ tb === WrapStrategy.WRAP
+ ) {
+ docModel.updateDocumentDataPageSize(realWidth);
+ }
+
+ documentSkeleton.calculate();
+ documentSkeleton.getActualSize();
+ const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
+
+ const { height: fontHeight, width: fontWidth } = textLayout;
+
+ let paddingTop = 0;
+ switch (vt) {
+ case VerticalAlign.BOTTOM:
+ paddingTop = (cellHeight - MARGIN_V - fontHeight);
+ break;
+ case VerticalAlign.MIDDLE:
+ paddingTop = (cellHeight - MARGIN_V - fontHeight) / 2;
+ break;
+
+ default:
+ paddingTop = MARGIN_V;
+ break;
+ }
+
+ let paddingLeft = 0;
+ switch (ht) {
+ case HorizontalAlign.CENTER:
+ paddingLeft = (realWidth - fontWidth) / 2;
+ break;
+ case HorizontalAlign.RIGHT:
+ paddingLeft = (realWidth - fontWidth);
+ break;
+
+ default:
+ break;
+ }
+
+ ctx.translate(0, paddingTop);
+ ctx.save();
+ ctx.translateWithPrecision(PADDING_H, 0);
+ ctx.beginPath();
+ ctx.rect(0, 0, realWidth, fontHeight);
+ ctx.clip();
+ documents.render(ctx);
+ ctx.translateWithPrecision(paddingLeft, 0);
+ ctx.restore();
+
+ ctx.restore();
+
+ map.set(key, {
+ left: cellBounding.endX + skeleton.rowHeaderWidth - ICON_PLACE,
+ top: cellBounding.startY + skeleton.columnHeaderHeight,
+ width: ICON_PLACE,
+ height: cellHeight,
+ });
+ } else {
+ ctx.save();
+ ctx.translateWithPrecision(cellBounding.startX, cellBounding.startY);
+ ctx.beginPath();
+ ctx.rect(0, 0, cellWidth, cellHeight);
+ ctx.clip();
+
+ const realWidth = cellWidth - (MARGIN_H * 2) - PADDING_H - ICON_PLACE;
+ const { documentSkeleton, documents, docModel } = createDocuments(valueStr, this._localeService, style);
+ if (
+ tb === WrapStrategy.WRAP
+ ) {
+ docModel.updateDocumentDataPageSize(realWidth);
+ }
+
+ documentSkeleton.calculate();
+ const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
+
+ const { height: fontHeight, width: fontWidth } = textLayout;
+ let paddingTop = 0;
+ switch (vt) {
+ case VerticalAlign.BOTTOM:
+ paddingTop = (cellHeight - MARGIN_V - fontHeight);
+ break;
+ case VerticalAlign.MIDDLE:
+ paddingTop = (cellHeight - MARGIN_V - fontHeight) / 2;
+ break;
+
+ default:
+ paddingTop = MARGIN_V;
+ break;
+ }
+ let paddingLeft = 0;
+ switch (ht) {
+ case HorizontalAlign.CENTER:
+ paddingLeft = (realWidth - fontWidth) / 2;
+ break;
+ case HorizontalAlign.RIGHT:
+ paddingLeft = (realWidth - fontWidth);
+ break;
+
+ default:
+ break;
+ }
+
+ ctx.translate(MARGIN_H, paddingTop);
+ const rectWidth = cellWidth - MARGIN_H * 2;
+ const rectHeight = fontHeight;
+ Rect.drawWith(ctx, {
+ width: rectWidth,
+ height: rectHeight,
+ fill: activeItem?.color || DROP_DOWN_DEFAULT_COLOR,
+ radius: 8,
+ });
+ ctx.save();
+ ctx.translateWithPrecision(PADDING_H, 0);
+ ctx.beginPath();
+ ctx.rect(0, 0, realWidth, fontHeight);
+ ctx.clip();
+ ctx.translateWithPrecision(paddingLeft, 0);
+ documents.render(ctx);
+ ctx.restore();
+ ctx.translate(realWidth + PADDING_H + 4, (fontHeight - ICON_SIZE) / 2);
+ ctx.fillStyle = DROP_DOWN_ICON_COLOR;
+ ctx.fill(downPath);
+ ctx.restore();
+
+ map.set(key, {
+ left: cellBounding.startX + MARGIN_H + skeleton.rowHeaderWidth,
+ top: cellBounding.startY + paddingTop + skeleton.columnHeaderHeight,
+ width: rectWidth,
+ height: rectHeight,
+ });
+ }
+ }
+
+ calcCellAutoHeight(info: ICellRenderContext): number | undefined {
+ const { primaryWithCoord, style, data } = info;
+ const cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
+ const cellWidth = cellBounding.endX - cellBounding.startX;
+ const value = getCellValueOrigin(data);
+ const valueStr = `${value ?? ''}`;
+
+ const rule = data.dataValidation?.rule;
+
+ if (!rule) {
+ return;
+ }
+
+ if (rule.renderMode === DataValidationRenderMode.TEXT) {
+ return undefined;
+ }
+
+ let { tb } = style || {};
+
+ tb = tb ?? WrapStrategy.WRAP;
+
+ if (rule.renderMode === DataValidationRenderMode.ARROW) {
+ const realWidth = cellWidth - ICON_PLACE;
+ const { documentSkeleton, docModel } = createDocSkeleton(valueStr, this._localeService, style);
+ if (
+ tb === WrapStrategy.WRAP
+ ) {
+ docModel.updateDocumentDataPageSize(realWidth);
+ }
+
+ documentSkeleton.calculate();
+ documentSkeleton.getActualSize();
+ const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
+
+ const { height: fontHeight } = textLayout;
+
+ return fontHeight;
+ } else {
+ const realWidth = cellWidth - (MARGIN_H * 2) - PADDING_H - ICON_PLACE;
+ const { documentSkeleton, docModel } = createDocSkeleton(valueStr, this._localeService, style);
+ if (
+ tb === WrapStrategy.WRAP
+ ) {
+ docModel.updateDocumentDataPageSize(realWidth);
+ }
+
+ documentSkeleton.calculate();
+ documentSkeleton.getActualSize();
+ const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
+
+ const {
+ height: fontHeight,
+ } = textLayout;
+
+ return fontHeight + (MARGIN_V * 2);
+ }
+ }
+
+ isHit(position: { x: number; y: number }, info: ICellRenderContext) {
+ const { data, subUnitId, row, col } = info;
+ const map = this._ensureMap(subUnitId);
+ const dropdownInfo = map.get(this._generateKey(row, col));
+ const validation = data.dataValidation;
+
+ if (!validation || !dropdownInfo) {
+ return false;
+ }
+ const { top, left, width, height } = dropdownInfo;
+ const { x, y } = position;
+
+ if (x >= left && (x <= (left + width)) && y >= top && (y <= (top + height))) {
+ return true;
+ }
+
+ return false;
+ };
+
+ onPointerDown(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ if (evt.button === 2) {
+ return;
+ }
+
+ const { unitId, subUnitId, row, col } = info;
+
+ const params: IShowDataValidationDropdownParams = {
+ unitId: unitId!,
+ subUnitId,
+ row,
+ column: col,
+ };
+
+ this._commandService.executeCommand(ShowDataValidationDropdown.id, params);
+ };
+}
diff --git a/packages/sheets-data-validation/src/widgets/shape/dropdown.ts b/packages/sheets-data-validation/src/widgets/shape/dropdown.ts
new file mode 100644
index 0000000000..255c223db6
--- /dev/null
+++ b/packages/sheets-data-validation/src/widgets/shape/dropdown.ts
@@ -0,0 +1,50 @@
+/**
+ * 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 type { IShapeProps, UniverRenderingContext } from '@univerjs/engine-render';
+import { Rect, Shape } from '@univerjs/engine-render';
+import { DROP_DOWN_DEFAULT_COLOR } from '../../common/const';
+import type { IDropdownLayoutInfo } from './layout';
+import { PADDING_H } from './layout';
+
+const RADIUS = 8;
+
+export interface IDropdownProps extends IShapeProps {
+ fontString: string;
+ fontFamily: string;
+ fontSize: number;
+ info: IDropdownLayoutInfo;
+ color: string;
+}
+
+export class Dropdown extends Shape<IDropdownProps> {
+ static override drawWith(ctx: UniverRenderingContext, props: IDropdownProps) {
+ const { fontFamily, fontString, fontSize, info, fill, color } = props;
+ const { layout, text } = info;
+ ctx.save();
+ Rect.drawWith(ctx, {
+ width: layout.width,
+ height: layout.height,
+ radius: RADIUS,
+ fill: fill || DROP_DOWN_DEFAULT_COLOR,
+ });
+ ctx.translateWithPrecision(PADDING_H, layout.ba);
+ ctx.font = fontString;
+ ctx.fillStyle = color;
+ ctx.fillText(text, 0, 0);
+ ctx.restore();
+ }
+}
diff --git a/packages/sheets-data-validation/src/widgets/shape/index.ts b/packages/sheets-data-validation/src/widgets/shape/index.ts
new file mode 100644
index 0000000000..02c0d24d26
--- /dev/null
+++ b/packages/sheets-data-validation/src/widgets/shape/index.ts
@@ -0,0 +1,19 @@
+/**
+ * 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.
+ */
+
+export { Dropdown } from './dropdown';
+export type { IDropdownProps } from './dropdown';
+export * from './layout';
diff --git a/packages/sheets-data-validation/src/widgets/shape/layout.ts b/packages/sheets-data-validation/src/widgets/shape/layout.ts
new file mode 100644
index 0000000000..bf83bc26e1
--- /dev/null
+++ b/packages/sheets-data-validation/src/widgets/shape/layout.ts
@@ -0,0 +1,112 @@
+/**
+ * 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 type { IStyleData, Nullable } from '@univerjs/core';
+import type { IDocumentSkeletonFontStyle } from '@univerjs/engine-render';
+import { FontCache, getFontStyleString } from '@univerjs/engine-render';
+
+export const PADDING_H = 4;
+export const PADDING_V = 0;
+export const MARGIN_H = 4;
+export const MARGIN_V = 4;
+export const CELL_PADDING_H = 6;
+export const CELL_PADDING_V = 6;
+export const ICON_PLACE = 14;
+
+export function measureDropdownItemText(text: string, style: Nullable<IStyleData>) {
+ const fontStyle = getFontStyleString(style ?? undefined);
+ const bBox = FontCache.getTextSize(text, fontStyle);
+ return bBox;
+}
+
+export function getDropdownItemSize(text: string, fontStyle: IDocumentSkeletonFontStyle) {
+ const bBox = FontCache.getTextSize(text, fontStyle);
+ const rectWidth = bBox.width + PADDING_H * 2;
+
+ const { ba, bd } = bBox;
+ const height = ba + bd;
+ return {
+ width: rectWidth,
+ height: height + (PADDING_V * 2),
+ ba,
+ };
+}
+
+export interface IDropdownLayoutInfo {
+ layout: {
+ width: number;
+ height: number;
+ ba: number;
+ };
+ text: string;
+}
+
+export interface IDropdownLine {
+ width: number;
+ height: number;
+ items: (IDropdownLayoutInfo & { left: number })[];
+}
+
+export function layoutDropdowns(items: string[], fontStyle: IDocumentSkeletonFontStyle, cellWidth: number, cellHeight: number) {
+ const contentWidth = cellWidth - ICON_PLACE - CELL_PADDING_H;
+ const contentHeight = cellHeight - CELL_PADDING_V * 2;
+ const textLayout = items.map((item) => ({
+ layout: getDropdownItemSize(item, fontStyle),
+ text: item,
+ }));
+
+ let currentLine: IDropdownLine | undefined;
+ const lines: IDropdownLine[] = [];
+
+ textLayout.forEach((item) => {
+ const { layout } = item;
+ const { width, height } = layout;
+
+ if (!currentLine || ((currentLine.width + width + MARGIN_H) > contentWidth)) {
+ currentLine = {
+ width,
+ height,
+ items: [{
+ ...item,
+ left: 0,
+ }],
+ };
+ lines.push(currentLine);
+ } else {
+ currentLine.items.push({
+ ...item,
+ left: currentLine.width + MARGIN_H,
+ });
+ currentLine.width = currentLine.width + width + MARGIN_H;
+ }
+ });
+ let totalHeight = 0;
+ lines.forEach((line, index) => {
+ if (index === lines.length - 1) {
+ totalHeight += line.height;
+ } else {
+ totalHeight += line.height + MARGIN_V;
+ }
+ });
+
+ return {
+ lines,
+ totalHeight,
+ contentWidth,
+ contentHeight,
+ cellAutoHeight: totalHeight + CELL_PADDING_V * 2,
+ };
+}
diff --git a/packages/sheets-data-validation/tsconfig.json b/packages/sheets-data-validation/tsconfig.json
new file mode 100644
index 0000000000..d676ad2a20
--- /dev/null
+++ b/packages/sheets-data-validation/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "extends": "@univerjs/shared/tsconfigs/base",
+ "compilerOptions": {
+ "rootDir": "src",
+ "outDir": "lib/types"
+ },
+ "references": [{ "path": "./tsconfig.node.json" }],
+ "include": ["src"]
+}
diff --git a/packages/sheets-data-validation/tsconfig.node.json b/packages/sheets-data-validation/tsconfig.node.json
new file mode 100644
index 0000000000..e53dac8868
--- /dev/null
+++ b/packages/sheets-data-validation/tsconfig.node.json
@@ -0,0 +1,4 @@
+{
+ "extends": "@univerjs/shared/tsconfigs/node",
+ "include": ["vite.config.ts"]
+}
diff --git a/packages/sheets-data-validation/vite.config.ts b/packages/sheets-data-validation/vite.config.ts
new file mode 100644
index 0000000000..e38cd8530b
--- /dev/null
+++ b/packages/sheets-data-validation/vite.config.ts
@@ -0,0 +1,12 @@
+import createViteConfig from '@univerjs/shared/vite';
+import pkg from './package.json';
+
+export default ({ mode }) => createViteConfig({}, {
+ mode,
+ pkg,
+ features: {
+ react: true,
+ css: true,
+ dom: true,
+ },
+});
diff --git a/packages/sheets-formula/src/formula-ui-plugin.ts b/packages/sheets-formula/src/formula-ui-plugin.ts
index 9c0569e51c..475dbd2f84 100644
--- a/packages/sheets-formula/src/formula-ui-plugin.ts
+++ b/packages/sheets-formula/src/formula-ui-plugin.ts
@@ -39,6 +39,7 @@ import {
import { FormulaPromptService, IFormulaPromptService } from './services/prompt.service';
import { IRegisterFunctionService, RegisterFunctionService } from './services/register-function.service';
import { NumfmtFormulaDisplayController } from './controllers/numfmt-formula-display.controller';
+import { FormulaRefRangeService } from './services/formula-ref-range.service';
/**
* The configuration of the formula UI plugin.
@@ -76,6 +77,7 @@ export class UniverSheetsFormulaPlugin extends Plugin {
[IFormulaCustomFunctionService, { useClass: FormulaCustomFunctionService }],
[IRegisterFunctionService, { useClass: RegisterFunctionService }],
+ [FormulaRefRangeService],
// controllers
[FormulaUIController],
diff --git a/packages/sheets-formula/src/index.ts b/packages/sheets-formula/src/index.ts
index 839dc85dfa..2dabd200fd 100644
--- a/packages/sheets-formula/src/index.ts
+++ b/packages/sheets-formula/src/index.ts
@@ -25,3 +25,4 @@ export {
export type { IRegisterFunctionParams, IUnregisterFunctionParams } from './services/register-function.service';
export { RegisterFunctionService } from './services/register-function.service';
export { IRegisterFunctionService } from './services/register-function.service';
+export { FormulaRefRangeService } from './services/formula-ref-range.service';
diff --git a/packages/sheets-formula/src/services/formula-ref-range.service.ts b/packages/sheets-formula/src/services/formula-ref-range.service.ts
new file mode 100644
index 0000000000..6f103a39be
--- /dev/null
+++ b/packages/sheets-formula/src/services/formula-ref-range.service.ts
@@ -0,0 +1,103 @@
+/**
+ * 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 type { IMutationInfo, IRange } from '@univerjs/core';
+import { Disposable, DisposableCollection, IUniverInstanceService } from '@univerjs/core';
+import { deserializeRangeWithSheet, ErrorType, generateStringWithSequence, LexerTreeBuilder, sequenceNodeType, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';
+import type { EffectRefRangeParams } from '@univerjs/sheets';
+import { handleDefaultRangeChangeWithEffectRefCommands, RefRangeService } from '@univerjs/sheets';
+import type { IDisposable } from '@wendellhu/redi';
+import { Inject } from '@wendellhu/redi';
+
+export type FormulaChangeMap = Record<string, Record<string, Record<string, string>>>;
+
+export type FormulaChangeCallback = (formulaString: string) => {
+ redos: IMutationInfo[];
+ undos: IMutationInfo[];
+};
+
+export class FormulaRefRangeService extends Disposable {
+ constructor(
+ @Inject(RefRangeService) private readonly _refRangeService: RefRangeService,
+ @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
+ ) {
+ super();
+ }
+
+ registerFormula(formula: string, callback: FormulaChangeCallback): IDisposable {
+ const rangeMap = new Map<string, { unitId: string; subUnitId: string; range: IRange; sheetName: string }>();
+ const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formula);
+ const disposableCollection = new DisposableCollection();
+ const handleChange = (params: EffectRefRangeParams) => {
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+ const unitId = workbook.getUnitId();
+ const subUnitId = worksheet.getSheetId();
+
+ const transformSequenceNodes = sequenceNodes?.map((node) => {
+ if (typeof node === 'object' && node.nodeType === sequenceNodeType.REFERENCE) {
+ const rangeInfo = rangeMap.get(node.token)!;
+ if ((rangeInfo.unitId && rangeInfo.unitId !== unitId) && (rangeInfo.subUnitId && rangeInfo.subUnitId !== subUnitId)) {
+ return node;
+ }
+ const newRange = handleDefaultRangeChangeWithEffectRefCommands(rangeInfo.range, params);
+
+ let newToken = '';
+ if (rangeInfo.unitId && rangeInfo.sheetName) {
+ newToken = serializeRangeWithSpreadsheet(rangeInfo.unitId, rangeInfo.sheetName, rangeInfo.range);
+ } else if (rangeInfo.sheetName) {
+ newToken = serializeRangeWithSheet(rangeInfo.sheetName, rangeInfo.range);
+ } else {
+ newToken = newRange ? serializeRange(newRange) : ErrorType.ERROR;
+ }
+
+ return {
+ ...node,
+ token: newToken,
+ };
+ } else {
+ return node;
+ }
+ ;
+ });
+ const newFormulaString = transformSequenceNodes && generateStringWithSequence(transformSequenceNodes);
+ return callback(`=${newFormulaString}`);
+ };
+ sequenceNodes?.forEach((node) => {
+ if (typeof node === 'object' && node.nodeType === sequenceNodeType.REFERENCE) {
+ const gridRangeName = deserializeRangeWithSheet(node.token);
+ const { range, unitId, sheetName } = gridRangeName;
+ const workbook = unitId ? this._univerInstanceService.getUniverSheetInstance(unitId) : this._univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = sheetName ? workbook?.getSheetBySheetName(sheetName) : workbook?.getActiveSheet();
+ if (!worksheet) {
+ return;
+ }
+ const sheetId = worksheet.getSheetId();
+ const item = {
+ unitId,
+ subUnitId: sheetId,
+ range,
+ sheetName,
+ };
+ rangeMap.set(node.token, item);
+ disposableCollection.add(this._refRangeService.registerRefRange(range, handleChange, unitId, sheetId));
+ }
+ });
+
+ return disposableCollection;
+ }
+}
diff --git a/packages/sheets-numfmt/src/components/currency/index.tsx b/packages/sheets-numfmt/src/components/currency/index.tsx
index aaa0879945..df81b65086 100644
--- a/packages/sheets-numfmt/src/components/currency/index.tsx
+++ b/packages/sheets-numfmt/src/components/currency/index.tsx
@@ -60,7 +60,7 @@ export const CurrencyPanel: FC<IBusinessComponentProps> = (props) => {
props.onChange(setPatternDecimal(pattern, decimal));
};
- const onChange = (value: string) => {
+ const onChange = (value: any) => {
patternSet(value);
props.onChange(setPatternDecimal(value, decimal));
};
diff --git a/packages/sheets-numfmt/src/components/date/index.tsx b/packages/sheets-numfmt/src/components/date/index.tsx
index dc4d9d0e52..03b47a01c2 100644
--- a/packages/sheets-numfmt/src/components/date/index.tsx
+++ b/packages/sheets-numfmt/src/components/date/index.tsx
@@ -49,7 +49,7 @@ export const DatePanel: FC<IBusinessComponentProps> = (props) => {
props.action.current = () => suffix;
- const onChange = (v: string) => {
+ const onChange = (v: any) => {
suffixSet(v);
props.onChange(v);
};
diff --git a/packages/sheets-numfmt/src/components/thousandth-percentile/index.tsx b/packages/sheets-numfmt/src/components/thousandth-percentile/index.tsx
index 5614ea1b58..168c7e9b4e 100644
--- a/packages/sheets-numfmt/src/components/thousandth-percentile/index.tsx
+++ b/packages/sheets-numfmt/src/components/thousandth-percentile/index.tsx
@@ -51,7 +51,7 @@ export const ThousandthPercentilePanel: FC<IBusinessComponentProps> = (props) =>
decimalSet(decimal || 0);
props.onChange(setPatternDecimal(suffix, Number(decimal || 0)));
};
- const handleClick = (v: string) => {
+ const handleClick = (v: any) => {
decimalSet(getDecimalFromPattern(v, 0));
suffixSet(v);
props.onChange(v);
diff --git a/packages/sheets-ui/src/common/utils.ts b/packages/sheets-ui/src/common/utils.ts
index 8b8924a6a4..6dd934c771 100644
--- a/packages/sheets-ui/src/common/utils.ts
+++ b/packages/sheets-ui/src/common/utils.ts
@@ -16,6 +16,7 @@
import type { ICellData, IMutationInfo, IRange, Nullable, Worksheet } from '@univerjs/core';
import { ObjectMatrix } from '@univerjs/core';
+import { Vector2 } from '@univerjs/engine-render';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '@univerjs/sheets';
import type { IAccessor } from '@wendellhu/redi';
@@ -92,6 +93,40 @@ export function getClearContentMutationParamForRange(
return redoMatrix;
}
+export function getCellIndexByOffsetWithMerge(offsetX: number, offsetY: number, scene: Scene, skeleton: SpreadsheetSkeleton) {
+ const activeViewport = scene.getActiveViewportByCoord(
+ Vector2.FromArray([offsetX, offsetY])
+ );
+
+ if (!activeViewport) {
+ return;
+ }
+
+ const { scaleX, scaleY } = scene.getAncestorScale();
+
+ const scrollXY = {
+ x: activeViewport.actualScrollX,
+ y: activeViewport.actualScrollY,
+ };
+
+ const cellPos = skeleton.getCellPositionByOffset(offsetX, offsetY, scaleX, scaleY, scrollXY);
+
+ const mergeCell = skeleton.mergeData.find((range) => {
+ const { startColumn, startRow, endColumn, endRow } = range;
+ return cellPos.row >= startRow && cellPos.column >= startColumn && cellPos.row <= endRow && cellPos.column <= endColumn;
+ });
+
+ const params = {
+ actualRow: mergeCell ? mergeCell.startRow : cellPos.row,
+ actualCol: mergeCell ? mergeCell.startColumn : cellPos.column,
+ mergeCell,
+ row: cellPos.row,
+ col: cellPos.column,
+ };
+
+ return params;
+}
+
export function getViewportByCell(row: number, column: number, scene: Scene, worksheet: Worksheet) {
const freeze = worksheet.getFreeze();
if (!freeze || (freeze.startRow <= 0 && freeze.startColumn <= 0)) {
diff --git a/packages/sheets-ui/src/controllers/cell-alert.controller.ts b/packages/sheets-ui/src/controllers/cell-alert.controller.ts
new file mode 100644
index 0000000000..4f3faef517
--- /dev/null
+++ b/packages/sheets-ui/src/controllers/cell-alert.controller.ts
@@ -0,0 +1,35 @@
+/**
+ * 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 { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import { ComponentManager } from '@univerjs/ui';
+import { Inject } from '@wendellhu/redi';
+import { CellAlert } from '../views/cell-alert/CellAlertPopup';
+import { CELL_ALERT_KEY } from '../views/cell-alert';
+
+@OnLifecycle(LifecycleStages.Starting, CellAlertController)
+export class CellAlertController extends Disposable {
+ constructor(
+ @Inject(ComponentManager) private _componentManager: ComponentManager
+ ) {
+ super();
+ this._initComponent();
+ }
+
+ private _initComponent() {
+ this._componentManager.register(CELL_ALERT_KEY, CellAlert);
+ }
+}
diff --git a/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts b/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
new file mode 100644
index 0000000000..f129441873
--- /dev/null
+++ b/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
@@ -0,0 +1,167 @@
+/**
+ * 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 type { Nullable } from '@univerjs/core';
+import { Disposable, DisposableCollection, IUniverInstanceService, LifecycleStages, OnLifecycle, sortRules } from '@univerjs/core';
+import type { IMouseEvent, IPointerEvent, Spreadsheet } from '@univerjs/engine-render';
+import { IRenderManagerService, Vector2 } from '@univerjs/engine-render';
+import { Inject } from '@wendellhu/redi';
+import type { ICellCustomRender, ICellRenderContext } from '@univerjs/core/types/interfaces/i-cell-custom-render.js';
+import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';
+
+@OnLifecycle(LifecycleStages.Ready, CellCustomRenderController)
+export class CellCustomRenderController extends Disposable {
+ private _enterActiveRender: Nullable<{
+ render: ICellCustomRender;
+ cellContext: ICellRenderContext;
+ }>;
+
+ constructor(
+ @Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
+ ) {
+ super();
+
+ this._initEventBinding();
+ }
+
+ private _initEventBinding() {
+ const disposableCollection = new DisposableCollection();
+ this._univerInstanceService.currentSheet$.subscribe((workbook) => {
+ if (workbook) {
+ const unitId = workbook.getUnitId();
+ const subUnitId = workbook.getActiveSheet().getSheetId();
+ const currentRender = this._renderManagerService.getRenderById(workbook.getUnitId());
+ if (currentRender && currentRender.mainComponent) {
+ disposableCollection.dispose();
+
+ const spreadsheet = currentRender.mainComponent as Spreadsheet;
+ const getActiveRender = (evt: IPointerEvent | IMouseEvent) => {
+ const skeleton = this._sheetSkeletonManagerService.getCurrent()?.skeleton!;
+ const { offsetX, offsetY } = evt;
+ const scene = currentRender.scene;
+ const worksheet = workbook.getActiveSheet();
+ const activeViewport = scene.getActiveViewportByCoord(
+ Vector2.FromArray([offsetX, offsetY])
+ );
+
+ if (!activeViewport) {
+ return;
+ }
+
+ const { scaleX, scaleY } = scene.getAncestorScale();
+
+ const scrollXY = {
+ x: activeViewport.actualScrollX,
+ y: activeViewport.actualScrollY,
+ };
+
+ const cellPos = skeleton.getCellPositionByOffset(offsetX, offsetY, scaleX, scaleY, scrollXY);
+
+ const mergeCell = skeleton.mergeData.find((range) => {
+ const { startColumn, startRow, endColumn, endRow } = range;
+ return cellPos.row >= startRow && cellPos.column >= startColumn && cellPos.row <= endRow && cellPos.column <= endColumn;
+ });
+
+ const cellIndex = {
+ actualRow: mergeCell ? mergeCell.startRow : cellPos.row,
+ actualCol: mergeCell ? mergeCell.startColumn : cellPos.column,
+ mergeCell,
+ row: cellPos.row,
+ col: cellPos.column,
+ };
+
+ if (!cellIndex || !skeleton) {
+ return;
+ }
+
+ const cellData = worksheet.getCell(cellIndex.actualRow, cellIndex.actualCol);
+ if (!cellData) {
+ return;
+ }
+
+ const renders = cellData.customRender;
+
+ if (!renders?.length) {
+ return;
+ }
+ const row = cellIndex.actualRow;
+ const col = cellIndex.actualCol;
+ const sortedRenders = renders.sort(sortRules);
+
+ const info: ICellRenderContext = {
+ data: cellData,
+ style: skeleton.getsStyles().getStyleByCell(cellData),
+ primaryWithCoord: skeleton.getCellByIndex(cellIndex.actualRow, cellIndex.actualCol),
+ unitId,
+ subUnitId,
+ row,
+ col,
+ };
+
+ const position = {
+ x: scrollXY.x + (offsetX / scaleX),
+ y: scrollXY.y + (offsetY / scaleY),
+ };
+
+ const activeRender = sortedRenders.find((render) => render.isHit?.(position, info));
+ if (!activeRender) {
+ return;
+ }
+ return [activeRender, info] as const;
+ };
+
+ const disposable = spreadsheet.onPointerDownObserver.add((evt) => {
+ const activeRenderInfo = getActiveRender(evt);
+ if (activeRenderInfo) {
+ const [activeRender, cellContext] = activeRenderInfo;
+ activeRender.onPointerDown?.(cellContext, evt);
+ }
+ });
+
+ const moveDisposable = spreadsheet.onPointerMoveObserver.add((evt) => {
+ const activeRenderInfo = getActiveRender(evt);
+ if (activeRenderInfo) {
+ const [activeRender, cellContext] = activeRenderInfo;
+ if (this._enterActiveRender) {
+ if (this._enterActiveRender.render !== activeRender) {
+ this._enterActiveRender.render.onPointerLeave?.(this._enterActiveRender.cellContext, evt);
+ this._enterActiveRender = {
+ render: activeRender,
+ cellContext,
+ };
+ activeRender.onPointerEnter?.(cellContext, evt);
+ }
+ } else {
+ this._enterActiveRender = {
+ render: activeRender,
+ cellContext,
+ };
+ activeRender.onPointerEnter?.(cellContext, evt);
+ }
+ }
+ });
+
+ disposable && disposableCollection.add(disposable);
+ moveDisposable && disposableCollection.add(moveDisposable);
+ }
+ }
+ });
+
+ this.disposeWithMe(disposableCollection);
+ }
+}
diff --git a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts
index d32e648c3e..ccdb23c30a 100644
--- a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts
@@ -121,7 +121,7 @@ export class EndEditController extends Disposable {
private _initialExitInput() {
this.disposeWithMe(
- this._editorBridgeService.visible$.subscribe((param) => {
+ this._editorBridgeService.visible$.subscribe(async (param) => {
const { visible, keycode, eventType } = param;
if (visible === this._editorVisiblePrevious) {
@@ -131,11 +131,11 @@ export class EndEditController extends Disposable {
this._editorVisiblePrevious = visible;
if (visible === true) {
- // Change `CursorChange` to changed status, when formula bar clicked.
+ // Change `CursorChange` to changed status, when formula bar clicked.
this._isCursorChange =
- eventType === DeviceInputEventType.PointerDown
- ? CursorChange.CursorChange
- : CursorChange.StartEditor;
+ eventType === DeviceInputEventType.PointerDown
+ ? CursorChange.CursorChange
+ : CursorChange.StartEditor;
return;
}
@@ -209,10 +209,30 @@ export class EndEditController extends Disposable {
row,
col: column,
};
+
+ /**
+ * When closing the editor, switch to the current tab of the editor.
+ */
+ if (workbookId === unitId && sheetId !== worksheetId && this._editorBridgeService.isForceKeepVisible()) {
+ this._commandService.executeCommand(SetWorksheetActivateCommand.id, {
+ subUnitId: sheetId,
+ unitId,
+ });
+ }
+ /**
+ * When switching tabs while the editor is open,
+ * the operation to refresh the selection will be blocked and needs to be triggered manually.
+ */
+ this._selectionManagerService.refreshSelection();
+
const cell = this._editorBridgeService.interceptor.fetchThroughInterceptors(
this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT
)(cellData, context);
+ const finalCell = await this._editorBridgeService.interceptor.fetchThroughInterceptors(
+ this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT_ASYNC
+ )(Promise.resolve(cell), context);
+
this._commandService.executeCommand(SetRangeValuesCommand.id, {
subUnitId: sheetId,
unitId,
@@ -222,27 +242,11 @@ export class EndEditController extends Disposable {
endRow: row,
endColumn: column,
},
- value: cell,
+ value: finalCell,
});
- // moveCursor need to put behind of SetRangeValuesCommand, fix https://github.com/dream-num/univer/issues/1155
+ // moveCursor need to put behind of SetRangeValuesCommand, fix https://github.com/dream-num/univer/issues/1155
this._moveCursor(keycode);
-
- /**
- * When closing the editor, switch to the current tab of the editor.
- */
- if (workbookId === unitId && sheetId !== worksheetId && this._editorBridgeService.isForceKeepVisible()) {
- this._commandService.executeCommand(SetWorksheetActivateCommand.id, {
- subUnitId: sheetId,
- unitId,
- });
- }
-
- /**
- * When switching tabs while the editor is open,
- * the operation to refresh the selection will be blocked and needs to be triggered manually.
- */
- this._selectionManagerService.refreshSelection();
})
);
}
diff --git a/packages/sheets-ui/src/controllers/hover.controller.ts b/packages/sheets-ui/src/controllers/hover.controller.ts
new file mode 100644
index 0000000000..c629290458
--- /dev/null
+++ b/packages/sheets-ui/src/controllers/hover.controller.ts
@@ -0,0 +1,57 @@
+/**
+ * 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 { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import { Inject } from '@wendellhu/redi';
+import { HoverManagerService } from '../services/hover-manager.service';
+
+@OnLifecycle(LifecycleStages.Rendered, HoverController)
+export class HoverController extends Disposable {
+ constructor(
+ @IRenderManagerService private _renderManagerService: IRenderManagerService,
+ @Inject(HoverManagerService) private _hoverManagerService: HoverManagerService,
+ @IUniverInstanceService private _univerInstanceService: IUniverInstanceService
+ ) {
+ super();
+
+ this._initPointerEvent();
+ }
+
+ private _initScrollEvent() {
+ // this.
+ }
+
+ private _initPointerEvent() {
+ const currentRender = this._renderManagerService.getRenderById(
+ this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId()
+ );
+ if (!currentRender) {
+ return;
+ }
+
+ const { scene } = currentRender;
+ const observer = scene.onPointerMoveObserver.add((evt) => {
+ this._hoverManagerService.onMouseMove(evt.offsetX, evt.offsetY);
+ });
+
+ this.disposeWithMe({
+ dispose() {
+ scene.onPointerMoveObserver.remove(observer);
+ },
+ });
+ }
+}
diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.ts
index b1a59e775b..8a7096d641 100644
--- a/packages/sheets-ui/src/index.ts
+++ b/packages/sheets-ui/src/index.ts
@@ -35,6 +35,7 @@ export {
} from './commands/commands/set-scroll.command';
export { VIEWPORT_KEY } from './common/keys';
export { AutoFillController } from './controllers/auto-fill.controller';
+export { CellCustomRenderController } from './controllers/cell-custom-render.controller';
export { PASTE_SPECIAL_MENU_ID } from './controllers/menu/menu';
export { whenFormulaEditorActivated } from './controllers/shortcuts/utils';
export {
@@ -75,6 +76,9 @@ export type { ISheetSkeletonManagerParam } from './services/sheet-skeleton-manag
export { SheetSkeletonManagerService } from './services/sheet-skeleton-manager.service';
export { UniverSheetsUIPlugin } from './sheets-ui-plugin';
export { SheetCanvasView } from './views/sheet-canvas-view';
+export { HoverManagerService } from './services/hover-manager.service';
+export { CellAlertManagerService, CellAlertType, type ICellAlert } from './services/cell-alert-manager.service';
+export { HoverController } from './controllers/hover.controller';
export { SHEET_VIEW_KEY } from './common/keys';
export { SheetCanvasPopManagerService } from './services/canvas-pop-manager.service';
export { mergeSetRangeValues } from './services/clipboard/utils';
diff --git a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
index e4f872e620..afeadef51f 100644
--- a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
+++ b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
@@ -35,6 +35,7 @@ interface ICanvasPopup {
onClickOutside?: (e: MouseEvent) => void;
direction?: 'vertical' | 'horizontal';
offset?: [number, number];
+ excludeOutside?: HTMLElement[];
}
export class SheetCanvasPopManagerService extends Disposable {
@@ -57,7 +58,8 @@ export class SheetCanvasPopManagerService extends Disposable {
) {
const { scene, engine } = currentRender;
- const cellInfo = skeleton.getCellByIndex(row, col);
+ const primaryWithCoord = skeleton.getCellByIndex(row, col);
+ const cellInfo = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
const { scaleX, scaleY } = scene.getAncestorScale();
diff --git a/packages/sheets-ui/src/services/cell-alert-manager.service.ts b/packages/sheets-ui/src/services/cell-alert-manager.service.ts
new file mode 100644
index 0000000000..752b4db722
--- /dev/null
+++ b/packages/sheets-ui/src/services/cell-alert-manager.service.ts
@@ -0,0 +1,85 @@
+/**
+ * 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 { Subject } from 'rxjs';
+import type { IDisposable } from '@wendellhu/redi';
+import { Inject } from '@wendellhu/redi';
+import type { Nullable } from '@univerjs/core';
+import type { ISheetLocation } from '@univerjs/sheets';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import { CELL_ALERT_KEY } from '../views/cell-alert';
+import { SheetCanvasPopManagerService } from './canvas-pop-manager.service';
+
+export enum CellAlertType {
+ INFO,
+ WARNING,
+ ERROR,
+}
+
+export interface ICellAlert {
+ type: CellAlertType;
+ title: React.ReactNode;
+ message: React.ReactNode;
+ location: ISheetLocation;
+ width: number;
+ height: number;
+}
+
+export class CellAlertManagerService {
+ private _currentAlert$ = new Subject<Nullable<ICellAlert>>();
+ private _currentPopup: Nullable<IDisposable> = undefined;
+
+ private _currentAlert: Nullable<ICellAlert> = null;
+
+ get currentAlert() {
+ return this._currentAlert;
+ }
+
+ currentAlert$ = this._currentAlert$.asObservable();
+
+ constructor(
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
+ @Inject(SheetCanvasPopManagerService) private readonly _canvasPopManagerService: SheetCanvasPopManagerService
+ ) {}
+
+ showAlert(alert: ICellAlert) {
+ this._currentPopup && this._currentPopup.dispose();
+ this._currentPopup = null;
+
+ const { location } = alert;
+ const { row, col, unitId } = location;
+
+ const currentRender = this._renderManagerService.getRenderById(unitId);
+ if (!currentRender) {
+ return;
+ }
+
+ this._currentAlert = alert;
+ this._currentAlert$.next(alert);
+ this._currentPopup = this._canvasPopManagerService.attachPopupToCell(row, col, {
+ componentKey: CELL_ALERT_KEY,
+ direction: 'horizontal',
+ offset: [2, 0],
+ });
+ }
+
+ clearAlert() {
+ this._currentPopup && this._currentPopup.dispose();
+ this._currentPopup = null;
+ this._currentAlert = null;
+ this._currentAlert$.next(null);
+ }
+}
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index b9b9d3f4ae..1e37978278 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -68,6 +68,7 @@ export interface IEditorBridgeServiceParam {
const BEFORE_CELL_EDIT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('BEFORE_CELL_EDIT');
const AFTER_CELL_EDIT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('AFTER_CELL_EDIT');
+const AFTER_CELL_EDIT_ASYNC = createInterceptorKey<Promise<Nullable<ICellDataForSheetInterceptor>>, ISheetLocation>('AFTER_CELL_EDIT_ASYNC');
export interface IEditorBridgeService {
currentEditCellState$: Observable<Nullable<IEditorBridgeServiceParam>>;
@@ -75,6 +76,7 @@ export interface IEditorBridgeService {
interceptor: InterceptorManager<{
BEFORE_CELL_EDIT: typeof BEFORE_CELL_EDIT;
AFTER_CELL_EDIT: typeof AFTER_CELL_EDIT;
+ AFTER_CELL_EDIT_ASYNC: typeof AFTER_CELL_EDIT_ASYNC;
}>;
dispose(): void;
refreshEditCellState(): void;
@@ -118,6 +120,7 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
interceptor = new InterceptorManager({
BEFORE_CELL_EDIT,
AFTER_CELL_EDIT,
+ AFTER_CELL_EDIT_ASYNC,
});
constructor(
@@ -153,6 +156,15 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
})
)
);
+
+ this.disposeWithMe(
+ toDisposable(
+ this.interceptor.intercept(this.interceptor.getInterceptPoints().AFTER_CELL_EDIT_ASYNC, {
+ priority: -1,
+ handler: (_value) => _value,
+ })
+ )
+ );
}
refreshEditCellState() {
diff --git a/packages/sheets-ui/src/services/hover-manager.service.ts b/packages/sheets-ui/src/services/hover-manager.service.ts
new file mode 100644
index 0000000000..5c3cc93dc2
--- /dev/null
+++ b/packages/sheets-ui/src/services/hover-manager.service.ts
@@ -0,0 +1,147 @@
+/**
+ * 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 type { IPosition, IRange, Nullable } from '@univerjs/core';
+import { IUniverInstanceService } from '@univerjs/core';
+import type { ISheetLocation } from '@univerjs/sheets';
+import { Inject } from '@wendellhu/redi';
+import { distinctUntilChanged, Subject } from 'rxjs';
+import { IRenderManagerService, Vector2 } from '@univerjs/engine-render';
+import { ISelectionRenderService } from '..';
+import { getCellIndexByOffsetWithMerge } from '../common/utils';
+import { ScrollManagerService } from './scroll-manager.service';
+import { SheetSkeletonManagerService } from './sheet-skeleton-manager.service';
+
+export interface IHoverCellPosition {
+ position: IPosition;
+ location: ISheetLocation;
+}
+
+export class HoverManagerService {
+ private _currentCell$ = new Subject<Nullable<IHoverCellPosition>>();
+ currentCell$ = this._currentCell$.asObservable().pipe(distinctUntilChanged((
+ (pre, aft) => (
+ pre?.location?.unitId === aft?.location?.unitId
+ && pre?.location?.subUnitId === aft?.location?.subUnitId
+ && pre?.location?.row === aft?.location?.row
+ && pre?.location?.col === aft?.location?.col
+ )
+ )));
+
+ private _lastPosition: Nullable<{ offsetX: number; offsetY: number }> = null;
+
+ constructor(
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(ScrollManagerService) private readonly _scrollManagerService: ScrollManagerService,
+ @Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
+ @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService
+ ) { }
+
+ private _calcActiveCell() {
+ if (!this._lastPosition) {
+ return;
+ }
+ const { offsetX, offsetY } = this._lastPosition;
+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
+ const worksheet = workbook.getActiveSheet();
+ const skeletonParam = this._sheetSkeletonManagerService.getCurrent();
+ const currentRender = this._renderManagerService.getRenderById(workbook.getUnitId());
+
+ const scrollInfo = this._scrollManagerService.getCurrentScroll();
+
+ if (!skeletonParam || !scrollInfo || !currentRender) {
+ return;
+ }
+
+ const { scene } = currentRender;
+
+ const { skeleton, sheetId, unitId } = skeletonParam;
+
+ const cellIndex = getCellIndexByOffsetWithMerge(offsetX, offsetY, scene, skeleton);
+
+ if (!cellIndex) {
+ this._currentCell$.next(null);
+ return;
+ }
+ const { row, col, mergeCell, actualCol, actualRow } = cellIndex;
+
+ const params: ISheetLocation = {
+ unitId,
+ subUnitId: sheetId,
+ workbook,
+ worksheet,
+ row: actualRow,
+ col: actualCol,
+ };
+
+ let anchorCell: IRange;
+
+ if (mergeCell) {
+ anchorCell = mergeCell;
+ } else {
+ anchorCell = {
+ startRow: row,
+ endRow: row,
+ startColumn: col,
+ endColumn: col,
+ };
+ }
+
+ const activeViewport = scene.getActiveViewportByCoord(
+ Vector2.FromArray([offsetX, offsetY])
+ );
+
+ if (!activeViewport) {
+ return;
+ }
+
+ const { scaleX, scaleY } = scene.getAncestorScale();
+
+ const scrollXY = {
+ x: activeViewport.actualScrollX,
+ y: activeViewport.actualScrollY,
+ };
+
+ const position: IPosition = {
+ startX: (skeleton.getOffsetByPositionX(anchorCell.startColumn - 1) - scrollXY.x) * scaleX,
+ endX: (skeleton.getOffsetByPositionX(anchorCell.endColumn) - scrollXY.x) * scaleX,
+ startY: (skeleton.getOffsetByPositionY(anchorCell.startRow - 1) - scrollXY.y) * scaleY,
+ endY: (skeleton.getOffsetByPositionY(anchorCell.endRow) - scrollXY.y) * scaleY,
+ };
+
+ this._currentCell$.next({
+ location: params,
+ position,
+ });
+ }
+
+ onMouseMove(offsetX: number, offsetY: number) {
+ this._lastPosition = {
+ offsetX,
+ offsetY,
+ };
+ this._calcActiveCell();
+ }
+
+ onScrollStart() {
+ this._currentCell$.next(null);
+ }
+
+ onScrollEnd() {
+ this._calcActiveCell();
+ }
+}
diff --git a/packages/sheets-ui/src/sheets-ui-plugin.ts b/packages/sheets-ui/src/sheets-ui-plugin.ts
index 238033f2f4..fd7cd215c4 100644
--- a/packages/sheets-ui/src/sheets-ui-plugin.ts
+++ b/packages/sheets-ui/src/sheets-ui-plugin.ts
@@ -62,6 +62,11 @@ import { SheetSkeletonManagerService } from './services/sheet-skeleton-manager.s
import { ShortcutExperienceService } from './services/shortcut-experience.service';
import { IStatusBarService, StatusBarService } from './services/status-bar.service';
import { SheetCanvasView } from './views/sheet-canvas-view';
+import { HoverController } from './controllers/hover.controller';
+import { HoverManagerService } from './services/hover-manager.service';
+import { CellAlertManagerService } from './services/cell-alert-manager.service';
+import { CellAlertController } from './controllers/cell-alert.controller';
+import { CellCustomRenderController } from './controllers/cell-custom-render.controller';
import { SheetCanvasPopManagerService } from './services/canvas-pop-manager.service';
export class UniverSheetsUIPlugin extends Plugin {
@@ -105,7 +110,9 @@ export class UniverSheetsUIPlugin extends Plugin {
],
[IStatusBarService, { useClass: StatusBarService }],
[IMarkSelectionService, { useClass: MarkSelectionService }],
+ [HoverManagerService],
[SheetCanvasPopManagerService],
+ [CellAlertManagerService],
// controllers
[ActiveWorksheetController],
@@ -133,6 +140,9 @@ export class UniverSheetsUIPlugin extends Plugin {
[StatusBarController],
[EditingController],
[MarkSelectionController],
+ [HoverController],
+ [CellAlertController],
+ [CellCustomRenderController],
] as Dependency[]
).forEach((d) => injector.add(d));
}
diff --git a/packages/sheets-ui/src/views/cell-alert/CellAlertPopup.tsx b/packages/sheets-ui/src/views/cell-alert/CellAlertPopup.tsx
new file mode 100644
index 0000000000..de64b7c6e6
--- /dev/null
+++ b/packages/sheets-ui/src/views/cell-alert/CellAlertPopup.tsx
@@ -0,0 +1,46 @@
+/**
+ * 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 { useDependency } from '@wendellhu/redi/react-bindings';
+import { useObservable } from '@univerjs/ui';
+import React from 'react';
+import { ErrorSingle, WarningSingle } from '@univerjs/icons';
+import cs from 'clsx';
+import { CellAlertManagerService, CellAlertType } from '../../services/cell-alert-manager.service';
+import styles from './index.module.less';
+
+export function CellAlert() {
+ const cellAlertService = useDependency(CellAlertManagerService);
+ const currentCell = useObservable(cellAlertService.currentAlert$, cellAlertService.currentAlert);
+
+ const { type, title, message } = currentCell || {};
+
+ const iconMap = {
+ [CellAlertType.ERROR]: <ErrorSingle className={cs(styles.cellAlertIcon, styles.cellAlertIconError)} />,
+ [CellAlertType.INFO]: <WarningSingle className={cs(styles.cellAlertIcon, styles.cellAlertIconInfo)} />,
+ [CellAlertType.WARNING]: <WarningSingle className={cs(styles.cellAlertIcon, styles.cellAlertIconWarning)} />,
+ };
+
+ return (
+ <div className={styles.cellAlert}>
+ <div className={styles.cellAlertTitle}>
+ {type ? iconMap[type] : null}
+ {title}
+ </div>
+ <div className={styles.cellAlertContent}>{message}</div>
+ </div>
+ );
+}
diff --git a/packages/sheets-ui/src/views/cell-alert/index.module.less b/packages/sheets-ui/src/views/cell-alert/index.module.less
new file mode 100644
index 0000000000..036c77b672
--- /dev/null
+++ b/packages/sheets-ui/src/views/cell-alert/index.module.less
@@ -0,0 +1,42 @@
+.cell-alert {
+ box-sizing: border-box;
+ box-shadow: var(--box-shadow-base);
+ padding: var(--padding-sm) var(--padding-base);
+ border-radius: var(--border-radius-lg);
+ color: rgba(var(--color-black));
+ background: rgba(var(--color-white));
+ z-index: 100;
+ width: 156px;
+
+ &-title {
+ height: 20px;
+ font-size: var(--font-size-sm);
+ font-weight: 500;
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ margin-bottom: 6px;
+ line-height: 20px;
+ }
+
+ &-icon {
+ margin-right: 6px;
+ }
+
+ &-icon-error {
+ color: rgba(var(--red-400));
+ }
+
+ &-icon-info {
+ color: rgba(var(--blue-500));
+ }
+
+ &-icon-warning {
+ color: rgba(var(--gold-400));
+ }
+
+ &-content {
+ font-size: var(--font-size-sm);
+ word-break: break-all;
+ }
+}
diff --git a/packages/sheets-ui/src/views/cell-alert/index.ts b/packages/sheets-ui/src/views/cell-alert/index.ts
new file mode 100644
index 0000000000..237db2c6f4
--- /dev/null
+++ b/packages/sheets-ui/src/views/cell-alert/index.ts
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+export { CellAlert } from './CellAlertPopup';
+
+const CELL_ALERT_KEY = 'univer.sheet.cell-alert';
+
+export {
+ CELL_ALERT_KEY,
+};
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 51b43cdf66..2eb9ade045 100644
--- a/packages/sheets/src/commands/commands/set-range-values.command.ts
+++ b/packages/sheets/src/commands/commands/set-range-values.command.ts
@@ -62,7 +62,6 @@ export const SetRangeValuesCommand: ICommand = {
unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId(),
subUnitId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId(),
} = params;
-
const currentSelections = range ? [range] : selectionManagerService.getSelectionRanges();
if (!currentSelections || !currentSelections.length) {
return false;
diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts
index 84e06f14be..a10689ef98 100644
--- a/packages/sheets/src/index.ts
+++ b/packages/sheets/src/index.ts
@@ -278,6 +278,7 @@ export {
rotateRange,
runRefRangeMutations,
handleDefaultRangeChangeWithEffectRefCommands,
+ handleOtherDefaultRangeChangeWithEffectRefCommands,
} from './services/ref-range/util';
export { INTERCEPTOR_POINT } from './services/sheet-interceptor/interceptor-const';
export { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';
diff --git a/packages/sheets/src/services/ref-range/ref-range.service.ts b/packages/sheets/src/services/ref-range/ref-range.service.ts
index b6d28b2fe0..a598ff2c76 100644
--- a/packages/sheets/src/services/ref-range/ref-range.service.ts
+++ b/packages/sheets/src/services/ref-range/ref-range.service.ts
@@ -192,6 +192,7 @@ export class RefRangeService extends Disposable {
},
{ redos: [], undos: [] }
);
+
const redos =
this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(
result.redos,
diff --git a/packages/sheets/src/services/ref-range/util.ts b/packages/sheets/src/services/ref-range/util.ts
index 04c37ecdeb..7c4980db04 100644
--- a/packages/sheets/src/services/ref-range/util.ts
+++ b/packages/sheets/src/services/ref-range/util.ts
@@ -15,7 +15,7 @@
*/
import type { ICommandInfo, IRange, Nullable } from '@univerjs/core';
-import { RANGE_TYPE, Rectangle } from '@univerjs/core';
+import { ObjectMatrix, queryObjectMatrix, Range, RANGE_TYPE, Rectangle } from '@univerjs/core';
import type {
IDeleteRangeMoveLeftCommand,
@@ -214,6 +214,28 @@ export const handleMoveRows = (params: IMoveRowsCommand, targetRange: IRange): I
];
};
+export const handleMoveRowsOther = (params: IMoveRowsCommand, targetRange: IRange) => {
+ const { fromRange, toRange } = params.params || {};
+ if (!fromRange || !toRange) {
+ return null;
+ }
+
+ const { startRow: fromRow } = fromRange;
+ const { startRow: toRow } = toRange;
+
+ const count = toRange.endRow - toRange.startRow + 1;
+
+ const matrix = new ObjectMatrix();
+
+ Range.foreach(targetRange, (row, col) => {
+ matrix.setValue(row, col, 1);
+ });
+
+ matrix.moveRows(fromRow, count, toRow);
+
+ return queryObjectMatrix(matrix, (value) => value === 1);
+};
+
export const handleMoveCols = (params: IMoveColsCommand, targetRange: IRange): IOperator[] => {
const { fromRange, toRange } = params.params || {};
if (!toRange || !fromRange) {
@@ -243,6 +265,28 @@ export const handleMoveCols = (params: IMoveColsCommand, targetRange: IRange): I
];
};
+export const handleMoveColsOther = (params: IMoveColsCommand, targetRange: IRange) => {
+ const { fromRange, toRange } = params.params || {};
+ if (!fromRange || !toRange) {
+ return null;
+ }
+
+ const { startColumn: fromCol } = fromRange;
+ const { startColumn: toCol } = toRange;
+
+ const count = toRange.endColumn - toRange.startColumn + 1;
+
+ const matrix = new ObjectMatrix();
+
+ Range.foreach(targetRange, (row, col) => {
+ matrix.setValue(row, col, 1);
+ });
+
+ matrix.moveColumns(fromCol, count, toCol);
+
+ return queryObjectMatrix(matrix, (value) => value === 1);
+};
+
export const handleMoveRange = (param: IMoveRangeCommand, targetRange: IRange) => {
const toRange = param.params?.toRange;
const fromRange = param.params?.fromRange;
@@ -273,6 +317,60 @@ export const handleMoveRange = (param: IMoveRangeCommand, targetRange: IRange) =
return operators;
};
+const handleMoveRangeOther = (param: IMoveRangeCommand, targetRange: IRange) => {
+ const toRange = param.params?.toRange;
+ const fromRange = param.params?.fromRange;
+ if (!toRange || !fromRange) {
+ return null;
+ }
+
+ if (Rectangle.contains(toRange, targetRange)) {
+ return null;
+ }
+
+ if (Rectangle.contains(fromRange, targetRange)) {
+ const relativeRange = Rectangle.getRelativeRange(targetRange, fromRange);
+ const positionRange = Rectangle.getPositionRange(relativeRange, toRange);
+ return positionRange;
+ }
+
+ const matrix = new ObjectMatrix();
+
+ Range.foreach(targetRange, (row, col) => {
+ matrix.setValue(row, col, 1);
+ });
+
+ const fromMatrix = new ObjectMatrix();
+ const loopFromRange = Rectangle.getIntersects(fromRange, targetRange);
+
+ loopFromRange && Range.foreach(loopFromRange, (row, col) => {
+ if (matrix.getValue(row, col)) {
+ matrix.setValue(row, col, undefined);
+ fromMatrix.setValue(row, col, 1);
+ }
+ });
+ const columnOffset = toRange.startColumn - fromRange.startColumn;
+ const rowOffset = toRange.startRow - fromRange.startRow;
+
+ const relativeToRange = {
+ startColumn: toRange.startColumn - columnOffset,
+ endColumn: toRange.endColumn - columnOffset,
+ startRow: toRange.startRow - rowOffset,
+ endRow: toRange.endRow - rowOffset,
+ };
+
+ const loopToRange = Rectangle.getIntersects(relativeToRange, targetRange);
+
+ loopToRange && Range.foreach(loopToRange, (row, col) => {
+ const targetRow = row + rowOffset;
+ const targetCol = col + columnOffset;
+ matrix.setValue(targetRow, targetCol, fromMatrix.getValue(row, col));
+ });
+
+ const res = queryObjectMatrix(matrix, (value) => value === 1);
+ return res;
+};
+
// see docs/tldr/ref-range/remove-rows-cols.tldr
export const handleBaseRemoveRange = (_removeRange: IRange, _targetRange: IRange) => {
const removeRange = handleRangeTypeInput(_removeRange);
@@ -542,47 +640,97 @@ export const runRefRangeMutations = (operators: IOperator[], range: IRange) => {
export const handleDefaultRangeChangeWithEffectRefCommands = (range: IRange, commandInfo: ICommandInfo) => {
let operator: IOperator[] = [];
switch (commandInfo.id) {
- case EffectRefRangId.DeleteRangeMoveLeftCommandId:{
+ case EffectRefRangId.DeleteRangeMoveLeftCommandId: {
operator = handleDeleteRangeMoveLeft(commandInfo as IDeleteRangeMoveLeftCommand, range);
break;
}
- case EffectRefRangId.DeleteRangeMoveUpCommandId:{
+ case EffectRefRangId.DeleteRangeMoveUpCommandId: {
operator = handleDeleteRangeMoveUp(commandInfo as IDeleteRangeMoveUpCommand, range);
break;
}
- case EffectRefRangId.InsertColCommandId:{
+ case EffectRefRangId.InsertColCommandId: {
operator = handleInsertCol(commandInfo as IInsertColCommand, range);
break;
}
- case EffectRefRangId.InsertRangeMoveDownCommandId:{
+ case EffectRefRangId.InsertRangeMoveDownCommandId: {
operator = handleInsertRangeMoveDown(commandInfo as IInsertRangeMoveDownCommand, range);
break;
}
- case EffectRefRangId.InsertRangeMoveRightCommandId:{
+ case EffectRefRangId.InsertRangeMoveRightCommandId: {
operator = handleInsertRangeMoveRight(commandInfo as IInsertRangeMoveRightCommand, range);
break;
}
- case EffectRefRangId.InsertRowCommandId:{
+ case EffectRefRangId.InsertRowCommandId: {
operator = handleInsertRow(commandInfo as IInsertRowCommand, range);
break;
}
- case EffectRefRangId.MoveColsCommandId:{
+ case EffectRefRangId.MoveColsCommandId: {
operator = handleMoveCols(commandInfo as IMoveColsCommand, range);
break;
}
- case EffectRefRangId.MoveRangeCommandId:{
+ case EffectRefRangId.MoveRangeCommandId: {
operator = handleMoveRange(commandInfo as IMoveRangeCommand, range);
break;
}
- case EffectRefRangId.MoveRowsCommandId:{
+ case EffectRefRangId.MoveRowsCommandId: {
operator = handleMoveRows(commandInfo as IMoveRowsCommand, range);
break;
}
- case EffectRefRangId.RemoveColCommandId:{
+ case EffectRefRangId.RemoveColCommandId: {
+ operator = handleIRemoveCol(commandInfo as IRemoveRowColCommand, range);
+ break;
+ }
+ case EffectRefRangId.RemoveRowCommandId: {
+ operator = handleIRemoveRow(commandInfo as IRemoveRowColCommand, range);
+ break;
+ }
+ }
+ const resultRange = runRefRangeMutations(operator, range);
+ return resultRange;
+};
+
+export const handleOtherDefaultRangeChangeWithEffectRefCommands = (range: IRange, commandInfo: ICommandInfo) => {
+ let operator: IOperator[] = [];
+ switch (commandInfo.id) {
+ case EffectRefRangId.DeleteRangeMoveLeftCommandId: {
+ operator = handleDeleteRangeMoveLeft(commandInfo as IDeleteRangeMoveLeftCommand, range);
+ break;
+ }
+ case EffectRefRangId.DeleteRangeMoveUpCommandId: {
+ operator = handleDeleteRangeMoveUp(commandInfo as IDeleteRangeMoveUpCommand, range);
+ break;
+ }
+
+ case EffectRefRangId.InsertRangeMoveDownCommandId: {
+ operator = handleInsertRangeMoveDown(commandInfo as IInsertRangeMoveDownCommand, range);
+ break;
+ }
+ case EffectRefRangId.InsertRangeMoveRightCommandId: {
+ operator = handleInsertRangeMoveRight(commandInfo as IInsertRangeMoveRightCommand, range);
+ break;
+ }
+ case EffectRefRangId.InsertColCommandId: {
+ operator = handleInsertCol(commandInfo as IInsertColCommand, range);
+ break;
+ }
+ case EffectRefRangId.InsertRowCommandId: {
+ operator = handleInsertRow(commandInfo as IInsertRowCommand, range);
+ break;
+ }
+ case EffectRefRangId.MoveColsCommandId: {
+ return handleMoveColsOther(commandInfo as IMoveColsCommand, range);
+ }
+ case EffectRefRangId.MoveRangeCommandId: {
+ return handleMoveRangeOther(commandInfo as IMoveRangeCommand, range);
+ }
+ case EffectRefRangId.MoveRowsCommandId: {
+ return handleMoveRowsOther(commandInfo as IMoveRowsCommand, range);
+ }
+ case EffectRefRangId.RemoveColCommandId: {
operator = handleIRemoveCol(commandInfo as IRemoveRowColCommand, range);
break;
}
- case EffectRefRangId.RemoveRowCommandId:{
+ case EffectRefRangId.RemoveRowCommandId: {
operator = handleIRemoveRow(commandInfo as IRemoveRowColCommand, range);
break;
}
diff --git a/packages/ui/src/components/custom-label/CustomLabel.tsx b/packages/ui/src/components/custom-label/CustomLabel.tsx
index 2d03c9c689..74c9102a32 100644
--- a/packages/ui/src/components/custom-label/CustomLabel.tsx
+++ b/packages/ui/src/components/custom-label/CustomLabel.tsx
@@ -30,7 +30,9 @@ export type ICustomLabelProps<T = undefined> = {
value$?: Observable<T>;
onChange?(v: string | number): void;
-} & Pick<IMenuSelectorItem<unknown>, 'label' | 'icon' | 'title'>;
+
+ title?: React.ReactNode;
+} & Pick<IMenuSelectorItem<unknown>, 'label' | 'icon'>;
/**
* The component to render toolbar item label and menu item label.
@@ -90,7 +92,7 @@ export function CustomLabel(props: ICustomLabelProps): JSX.Element | null {
}
}
if (title) {
- nodes.push(<span key={index++}>{localeService.t(title)}</span>);
+ nodes.push(<span key={index++}>{typeof title === 'string' ? localeService.t(title) : title}</span>);
}
return <>{nodes}</>;
diff --git a/packages/ui/src/components/hooks/event.ts b/packages/ui/src/components/hooks/event.ts
new file mode 100644
index 0000000000..13de094d08
--- /dev/null
+++ b/packages/ui/src/components/hooks/event.ts
@@ -0,0 +1,29 @@
+/**
+ * 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 { useCallback, useRef } from 'react';
+
+export function useEvent<T extends (...params: any[]) => any>(func: T) {
+ const funcRef = useRef(func);
+
+ funcRef.current = func;
+ return useCallback<T>(
+ ((...params) => {
+ return funcRef.current(...params);
+ }) as T,
+ []
+ );
+}
diff --git a/packages/ui/src/components/range-selector/RangeSelector.tsx b/packages/ui/src/components/range-selector/RangeSelector.tsx
index 79ba894915..9a77a8da8b 100644
--- a/packages/ui/src/components/range-selector/RangeSelector.tsx
+++ b/packages/ui/src/components/range-selector/RangeSelector.tsx
@@ -22,6 +22,7 @@ import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useRef, useState } from 'react';
import { deserializeRangeWithSheet, isReferenceString, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';
+import clsx from 'clsx';
import { TextEditor } from '../editor/TextEditor';
import { IEditorService } from '../../services/editor/editor.service';
import { IRangeSelectorService } from '../../services/range-selector/range-selector.service';
@@ -40,10 +41,11 @@ export interface IRangeSelectorProps {
width?: number; // The width of the selector.
size?: 'mini' | 'small' | 'middle' | 'large'; // The size of the selector.
placeholder?: string; // Placeholder text.
+ className?: string;
}
export function RangeSelector(props: IRangeSelectorProps) {
- const { onChange, id, value = '', width = 220, placeholder = '', size = 'middle', onActive, onValid, isSingleChoice = false, openForSheetUnitId, openForSheetSubUnitId, isReadonly = false } = props;
+ const { onChange, id, value = '', width = 220, placeholder = '', size = 'middle', onActive, onValid, isSingleChoice = false, openForSheetUnitId, openForSheetSubUnitId, isReadonly = false, className } = props;
const [rangeDataList, setRangeDataList] = useState<string[]>(['']);
@@ -311,7 +313,7 @@ export function RangeSelector(props: IRangeSelectorProps) {
onClose={handleCloseModal}
>
- <div className={styles.rangeSelectorModal}>
+ <div className={clsx(styles.rangeSelectorModal, className)}>
{rangeDataList.map((item, index) => (
<div key={index} className={styles.rangeSelectorModalContainer}>
<div style={{ width: rangeDataList.length === 1 ? '280px' : '252px' }} className={styles.rangeSelectorModalContainerInput}>
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index a71f5eb8ff..4a5534a5ee 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -19,6 +19,7 @@ export { getMenuHiddenObservable } from './common/menu-hidden-observable';
export * from './components';
export { t } from './components/hooks/locale';
export { useObservable } from './components/hooks/observable';
+export { useEvent } from './components/hooks/event';
export {
CopyShortcutItem,
CutShortcutItem,
diff --git a/packages/ui/src/services/popup/canvas-popup.service.ts b/packages/ui/src/services/popup/canvas-popup.service.ts
index fe411746df..9fa8c7ce0c 100644
--- a/packages/ui/src/services/popup/canvas-popup.service.ts
+++ b/packages/ui/src/services/popup/canvas-popup.service.ts
@@ -25,6 +25,7 @@ export interface IPopup {
anchorRect$: Observable<IBoundRectNoAngle>;
componentKey: string;
onClickOutside?: (e: MouseEvent) => void;
+ excludeOutside?: HTMLElement[];
unitId: string;
subUnitId: string;
direction?: 'vertical' | 'horizontal';
@@ -35,7 +36,6 @@ export interface ICanvasPopupService {
addPopup(item: IPopup): string;
removePopup(id: string): void;
removeAll(): void;
-
popups$: Observable<[string, IPopup][]>;
get popups(): [string, IPopup][];
diff --git a/packages/ui/src/views/App.tsx b/packages/ui/src/views/App.tsx
index 9a862f2c3f..5a55a84ba0 100644
--- a/packages/ui/src/views/App.tsx
+++ b/packages/ui/src/views/App.tsx
@@ -20,7 +20,6 @@ import { ConfigProvider, defaultTheme, themeInstance } from '@univerjs/design';
import { useDependency } from '@wendellhu/redi/react-bindings';
import type { ComponentType } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
-
import type { IWorkbenchOptions } from '../controllers/ui/ui.controller';
import { IMessageService } from '../services/message/message.service';
import styles from './app.module.less';
@@ -46,7 +45,6 @@ export function App(props: IUniverAppProps) {
const localeService = useDependency(LocaleService);
const themeService = useDependency(ThemeService);
const messageService = useDependency(IMessageService);
-
const contentRef = useRef<HTMLDivElement>(null);
useEffect(() => {
@@ -141,6 +139,7 @@ export function App(props: IUniverAppProps) {
)}
<ZenZone />
+
</section>
</div>
diff --git a/packages/ui/src/views/components/popup/CanvasPopup.tsx b/packages/ui/src/views/components/popup/CanvasPopup.tsx
index 301eb40060..e6c970c14b 100644
--- a/packages/ui/src/views/components/popup/CanvasPopup.tsx
+++ b/packages/ui/src/views/components/popup/CanvasPopup.tsx
@@ -40,6 +40,7 @@ const SingleCanvasPopup = ({ popup, children }: { popup: IPopup; children?: Reac
anchorRect={rect}
direction={popup.direction}
onClickOutside={popup.onClickOutside}
+ excludeOutside={popup.excludeOutside}
>
{children}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bcd0f4dfc9..24e973caa7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -186,6 +186,9 @@ importers:
'@univerjs/core':
specifier: workspace:*
version: link:../packages/core
+ '@univerjs/data-validation':
+ specifier: workspace:*
+ version: link:../packages/data-validation
'@univerjs/design':
specifier: workspace:*
version: link:../packages/design
@@ -222,6 +225,9 @@ importers:
'@univerjs/sheets-conditional-formatting-ui':
specifier: workspace:*
version: link:../packages/sheets-conditional-formatting-ui
+ '@univerjs/sheets-data-validation':
+ specifier: workspace:*
+ version: link:../packages/sheets-data-validation
'@univerjs/sheets-find-replace':
specifier: workspace:*
version: link:../packages/sheets-find-replace
@@ -343,7 +349,71 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
+
+ packages/data-validation:
+ dependencies:
+ '@univerjs/core':
+ specifier: '*'
+ version: link:../core
+ '@wendellhu/redi':
+ specifier: ^0.13.0
+ version: 0.13.0
+ dayjs:
+ specifier: ^1.11.10
+ version: 1.11.10
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
+ devDependencies:
+ '@univerjs/design':
+ specifier: workspace:*
+ version: link:../design
+ '@univerjs/docs':
+ specifier: workspace:*
+ version: link:../docs
+ '@univerjs/engine-formula':
+ specifier: workspace:*
+ version: link:../engine-formula
+ '@univerjs/engine-numfmt':
+ specifier: workspace:*
+ version: link:../engine-numfmt
+ '@univerjs/engine-render':
+ specifier: workspace:*
+ version: link:../engine-render
+ '@univerjs/network':
+ specifier: workspace:*
+ version: link:../network
+ '@univerjs/rpc':
+ specifier: workspace:*
+ version: link:../rpc
+ '@univerjs/shared':
+ specifier: workspace:*
+ version: link:../../common/shared
+ '@univerjs/sheets':
+ specifier: workspace:*
+ version: link:../sheets
+ '@univerjs/sheets-formula':
+ specifier: workspace:*
+ version: link:../sheets-formula
+ '@vitest/coverage-istanbul':
+ specifier: ^1.2.1
+ version: 1.4.0([email protected])
+ typescript:
+ specifier: ^5.3.3
+ version: 5.4.3
+ vite:
+ specifier: ^5.0.11
+ version: 5.2.7(@types/[email protected])([email protected])
+ vite-plugin-dts:
+ specifier: ^3.7.1
+ vite-plugin-externals:
+ specifier: ^0.6.2
+ version: 0.6.2([email protected])
+ vitest:
+ specifier: ^1.2.1
+ version: 1.4.0(@types/[email protected])([email protected])
packages/design:
dependencies:
@@ -431,7 +501,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/docs:
devDependencies:
@@ -458,7 +528,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/docs-ui:
devDependencies:
@@ -503,7 +573,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/engine-formula:
dependencies:
@@ -537,7 +607,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/engine-numfmt:
dependencies:
@@ -556,7 +626,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/engine-render:
dependencies:
@@ -587,7 +657,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/facade:
devDependencies:
@@ -693,7 +763,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/network:
devDependencies:
@@ -717,7 +787,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/rpc:
devDependencies:
@@ -741,7 +811,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/sheets:
devDependencies:
@@ -771,7 +841,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/sheets-conditional-formatting:
dependencies:
@@ -814,7 +884,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/sheets-conditional-formatting-ui:
dependencies:
@@ -826,7 +896,7 @@ importers:
version: link:../sheets-conditional-formatting
lodash.get:
specifier: ^4.4.2
- version: 4.4.2
+ version: r2.cnpmjs.org/[email protected]
lodash.set:
specifier: ^4.3.2
version: 4.3.2
@@ -899,7 +969,110 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+
+ packages/sheets-data-validation:
+ dependencies:
+ '@univerjs/core':
+ specifier: workspace:*
+ version: link:../core
+ '@univerjs/data-validation':
+ specifier: workspace:*
+ version: link:../data-validation
+ '@univerjs/design':
+ specifier: workspace:*
+ version: link:../design
+ '@univerjs/icons':
+ specifier: ^0.1.26
+ '@univerjs/ui':
+ specifier: workspace:*
+ version: link:../ui
+ '@wendellhu/redi':
+ specifier: ^0.13.0
+ version: 0.13.0
+ clsx:
+ specifier: ^2.1.0
+ version: 2.1.0
+ dayjs:
+ specifier: ^1.11.10
+ version: 1.11.10
+ react:
+ specifier: ^18.2.0
+ version: 18.2.0
+ react-draggable-list:
+ specifier: ^4.2.0
+ version: 4.2.0([email protected])
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
+ devDependencies:
+ '@univerjs/docs':
+ specifier: workspace:*
+ version: link:../docs
+ '@univerjs/docs-ui':
+ specifier: workspace:*
+ version: link:../docs-ui
+ '@univerjs/engine-formula':
+ specifier: workspace:*
+ version: link:../engine-formula
+ '@univerjs/engine-numfmt':
+ specifier: workspace:*
+ version: link:../engine-numfmt
+ '@univerjs/engine-render':
+ specifier: workspace:*
+ version: link:../engine-render
+ '@univerjs/network':
+ specifier: workspace:*
+ version: link:../network
+ '@univerjs/rpc':
+ specifier: workspace:*
+ version: link:../rpc
+ '@univerjs/shared':
+ specifier: workspace:*
+ version: link:../../common/shared
+ '@univerjs/sheets':
+ specifier: workspace:*
+ version: link:../sheets
+ '@univerjs/sheets-formula':
+ specifier: workspace:*
+ version: link:../sheets-formula
+ '@univerjs/sheets-numfmt':
+ specifier: workspace:*
+ version: link:../sheets-numfmt
+ '@univerjs/sheets-ui':
+ specifier: workspace:*
+ version: link:../sheets-ui
+ '@univerjs/uniscript':
+ specifier: workspace:*
+ version: link:../uniscript
+ '@vitejs/plugin-react':
+ specifier: ^4.2.1
+ version: 4.2.1([email protected])
+ '@vitest/coverage-istanbul':
+ specifier: ^1.2.1
+ version: 1.4.0([email protected])
+ happy-dom:
+ specifier: ^13.0.0
+ version: 13.3.8
+ less:
+ specifier: ^4.2.0
+ version: 4.2.0
+ typescript:
+ specifier: ^5.3.3
+ version: 5.4.3
+ vite:
+ specifier: ^5.0.11
+ version: 5.2.7(@types/[email protected])([email protected])
+ vite-plugin-dts:
+ specifier: ^3.7.1
+ vite-plugin-externals:
+ specifier: ^0.6.2
+ version: 0.6.2([email protected])
+ vitest:
+ specifier: ^1.2.1
packages/sheets-find-replace:
devDependencies:
@@ -938,7 +1111,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/sheets-formula:
dependencies:
@@ -1002,7 +1175,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/sheets-numfmt:
dependencies:
@@ -1060,7 +1233,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/sheets-ui:
dependencies:
@@ -1121,7 +1294,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/sheets-zen-editor:
dependencies:
@@ -1173,7 +1346,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/slides:
devDependencies:
@@ -1200,7 +1373,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
+ version: 1.4.0(@types/[email protected])([email protected])
packages/slides-ui:
devDependencies:
@@ -1245,7 +1418,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/ui:
dependencies:
@@ -1322,7 +1495,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages/uniscript:
dependencies:
@@ -1371,7 +1544,7 @@ importers:
version: 5.2.7(@types/[email protected])([email protected])
vitest:
specifier: ^1.4.0
- version: 1.4.0(@types/[email protected])([email protected])
packages:
@@ -1494,7 +1667,7 @@ packages:
engines: {node: '>=6.9.0'}
dependencies:
'@babel/highlight': 7.24.2
- picocolors: 1.0.0
+ picocolors: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-Pc65opHDliVpRHuKfzI+gSA4zcgr65O4cl64fFJIWEEh8JoHIHh0Oez1Eo8Arz8zq/JhgKodQaxEwUPRtZylVA==}
@@ -2695,7 +2868,7 @@ packages:
'@babel/core': 7.24.3
clone-deep: 4.0.1
find-cache-dir: 2.1.0
- make-dir: 2.1.0
+ make-dir: r2.cnpmjs.org/[email protected]
pirates: 4.0.6
source-map-support: 0.5.21
dev: false
@@ -2764,7 +2937,7 @@ packages:
resolution: {integrity: sha512-H4hxZDXgHtWTwV3RAVenqcC4VbJZNegbBjlPvzOzCouXtS2y3sDvlO3IsbrPNWuLWPPlYVYPghQdSF64683Ldw==}
dependencies:
- picocolors: 1.0.0
+ picocolors: r2.cnpmjs.org/[email protected]
sisteransi: 1.0.5
dev: true
@@ -2772,7 +2945,7 @@ packages:
resolution: {integrity: sha512-0MhX9/B4iL6Re04jPrttDm+BsP8y6mS7byuv0BvXgdXhbV5PdlsHt55dvNsuBCPZ7xq1oTAOOuotR9NFbQyMSA==}
dependencies:
'@clack/core': 0.3.4
- picocolors: 1.0.0
+ picocolors: r2.cnpmjs.org/[email protected]
sisteransi: 1.0.5
dev: true
bundledDependencies:
@@ -3238,7 +3411,7 @@ packages:
engines: {node: '>=6'}
hasBin: true
dependencies:
- lodash.camelcase: 4.3.0
+ lodash.camelcase: r2.cnpmjs.org/[email protected]
long: 5.2.3
protobufjs: 7.2.6
yargs: 17.7.2
@@ -3315,6 +3488,7 @@ packages:
engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [arm64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
dev: true
optional: true
@@ -3324,6 +3498,7 @@ packages:
engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [arm]
os: [linux]
+ libc: [glibc]
requiresBuild: true
dev: true
optional: true
@@ -3333,6 +3508,7 @@ packages:
engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [s390x]
os: [linux]
+ libc: [glibc]
requiresBuild: true
dev: true
optional: true
@@ -3342,6 +3518,7 @@ packages:
engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [x64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
dev: true
optional: true
@@ -3351,6 +3528,7 @@ packages:
engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [arm64]
os: [linux]
+ libc: [musl]
requiresBuild: true
dev: true
optional: true
@@ -3360,6 +3538,7 @@ packages:
engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [x64]
os: [linux]
+ libc: [musl]
requiresBuild: true
dev: true
optional: true
@@ -3369,6 +3548,7 @@ packages:
engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [arm64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optionalDependencies:
'@img/sharp-libvips-linux-arm64': 1.0.2
@@ -3380,6 +3560,7 @@ packages:
engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [arm]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optionalDependencies:
'@img/sharp-libvips-linux-arm': 1.0.2
@@ -3391,6 +3572,7 @@ packages:
engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [s390x]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optionalDependencies:
'@img/sharp-libvips-linux-s390x': 1.0.2
@@ -3402,6 +3584,7 @@ packages:
engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [x64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optionalDependencies:
'@img/sharp-libvips-linux-x64': 1.0.2
@@ -3413,6 +3596,7 @@ packages:
engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [arm64]
os: [linux]
+ libc: [musl]
requiresBuild: true
optionalDependencies:
'@img/sharp-libvips-linuxmusl-arm64': 1.0.2
@@ -3424,6 +3608,7 @@ packages:
engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'}
cpu: [x64]
os: [linux]
+ libc: [musl]
requiresBuild: true
optionalDependencies:
'@img/sharp-libvips-linuxmusl-x64': 1.0.2
@@ -3463,16 +3648,15 @@ packages:
engines: {node: '>=12'}
dependencies:
string-width: 5.1.2
- string-width-cjs: /[email protected]
+ string-width-cjs: r2.cnpmjs.org/[email protected]
strip-ansi: 7.1.0
- strip-ansi-cjs: /[email protected]
+ strip-ansi-cjs: r2.cnpmjs.org/[email protected]
wrap-ansi: 8.1.0
- wrap-ansi-cjs: /[email protected]
+ wrap-ansi-cjs: r2.cnpmjs.org/[email protected]
/@istanbuljs/[email protected]:
resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==}
engines: {node: '>=8'}
- dev: false
resolution: {integrity: sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==}
@@ -3542,7 +3726,6 @@ packages:
'@rushstack/node-core-library': 4.0.2(@types/[email protected])
transitivePeerDependencies:
- '@types/node'
- dev: false
resolution: {integrity: sha512-GFhTcJpB+MI6FhvXEI9b2K0snulNLWHqC/BbcJtyNYcKUiw7l3Lgis5ApsYncJ0leALX7/of4XfmXk+maT111w==}
@@ -3563,20 +3746,17 @@ packages:
typescript: 5.4.2
transitivePeerDependencies:
- '@types/node'
- dev: false
/@microsoft/[email protected]:
resolution: {integrity: sha512-OGiIzzoBLgWWR0UdRJX98oYO+XKGf7tiK4Zk6tQ/E4IJqGCe7dvkTvgDZV5cFJUzLGDOjeAXrnZoA6QkVySuxw==}
dependencies:
'@microsoft/tsdoc': 0.14.2
- ajv: 6.12.6
- jju: 1.4.0
- resolve: 1.19.0
- dev: false
+ ajv: r2.cnpmjs.org/[email protected]
+ jju: r2.cnpmjs.org/[email protected]
+ resolve: r2.cnpmjs.org/[email protected]
/@microsoft/[email protected]:
resolution: {integrity: sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==}
- dev: false
/@ndelangen/[email protected]:
resolution: {integrity: sha512-9JKTEik4vq+yGosHYhZ1tiH/3WpUS0Nh0kej4Agndhox8pAdWhEx5knFVRcb/ya9knCRCs1rPxNrSXTDdfVqpA==}
@@ -3747,49 +3927,6 @@ packages:
config-chain: 1.1.13
dev: true
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==}
- dependencies:
- '@protobufjs/aspromise': 1.1.2
- '@protobufjs/inquire': 1.1.0
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==}
- dev: false
-
- /@protobufjs/[email protected]:
- resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==}
- dev: false
-
resolution: {integrity: sha512-fDSBgd44FKHa1FRMU59qBMPFcl2PZE+2nmqunj+BWFyYYjnhIDWL2ItDs3rrbJDQOtzt5nIebLCQc4QRfz6LJw==}
peerDependencies:
@@ -3941,7 +4078,6 @@ packages:
'@types/estree': 1.0.5
estree-walker: 2.0.2
picomatch: 2.3.1
- dev: false
resolution: {integrity: sha512-3XFIDKWMFZrMnao1mJhnOT1h2g0169Os848NhhmGweEcfJ4rCi+3yMCOLG4zA61rbJdkcrM/DjVZm9Hg5p5w7g==}
@@ -3982,6 +4118,7 @@ packages:
resolution: {integrity: sha512-L1+D8/wqGnKQIlh4Zre9i4R4b4noxzH5DDciyahX4oOz62CphY7WDWqJoQ66zNR4oScLNOqQJfNSIAe/6TPUmQ==}
cpu: [arm64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optional: true
@@ -3989,6 +4126,7 @@ packages:
resolution: {integrity: sha512-tK5eoKFkXdz6vjfkSTCupUzCo40xueTOiOO6PeEIadlNBkadH1wNOH8ILCPIl8by/Gmb5AGAeQOFeLev7iZDOA==}
cpu: [arm64]
os: [linux]
+ libc: [musl]
requiresBuild: true
optional: true
@@ -3996,6 +4134,7 @@ packages:
resolution: {integrity: sha512-zvXvAUGGEYi6tYhcDmb9wlOckVbuD+7z3mzInCSTACJ4DQrdSLPNUeDIcAQW39M3q6PDquqLWu7pnO39uSMRzQ==}
cpu: [ppc64le]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optional: true
@@ -4003,6 +4142,7 @@ packages:
resolution: {integrity: sha512-C3GSKvMtdudHCN5HdmAMSRYR2kkhgdOfye4w0xzyii7lebVr4riCgmM6lRiSCnJn2w1Xz7ZZzHKuLrjx5620kw==}
cpu: [riscv64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optional: true
@@ -4010,6 +4150,7 @@ packages:
resolution: {integrity: sha512-l4U0KDFwzD36j7HdfJ5/TveEQ1fUTjFFQP5qIt9gBqBgu1G8/kCaq5Ok05kd5TG9F8Lltf3MoYsUMw3rNlJ0Yg==}
cpu: [s390x]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optional: true
@@ -4017,6 +4158,7 @@ packages:
resolution: {integrity: sha512-xXMLUAMzrtsvh3cZ448vbXqlUa7ZL8z0MwHp63K2IIID2+DeP5iWIT6g1SN7hg1VxPzqx0xZdiDM9l4n9LRU1A==}
cpu: [x64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
optional: true
@@ -4024,6 +4166,7 @@ packages:
resolution: {integrity: sha512-M/JYAWickafUijWPai4ehrjzVPKRCyDb1SLuO+ZyPfoXgeCEAlgPkNXewFZx0zcnoIe3ay4UjXIMdXQXOZXWqA==}
cpu: [x64]
os: [linux]
+ libc: [musl]
requiresBuild: true
optional: true
@@ -4057,20 +4200,18 @@ packages:
optional: true
dependencies:
'@types/node': 20.12.2
- fs-extra: 7.0.1
- import-lazy: 4.0.0
- jju: 1.4.0
+ fs-extra: r2.cnpmjs.org/[email protected]
+ import-lazy: r2.cnpmjs.org/[email protected]
+ jju: r2.cnpmjs.org/[email protected]
resolve: 1.22.8
semver: 7.5.4
z-schema: 5.0.5
- dev: false
/@rushstack/[email protected]:
resolution: {integrity: sha512-mUDecIJeH3yYGZs2a48k+pbhM6JYwWlgjs2Ca5f2n1G2/kgdgP9D/07oglEGf6mRyXEnazhEENeYTSNDRCwdqA==}
dependencies:
resolve: 1.22.8
- strip-json-comments: 3.1.1
- dev: false
+ strip-json-comments: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-UbELbXnUdc7EKwfH2sb8ChqNgapUOdqcCIdQP4NGxBpTZV2sQyeekuK3zmfQSa/MN+/7b4kBogl2wq0vpkpYGw==}
@@ -4083,18 +4224,16 @@ packages:
'@rushstack/node-core-library': 4.0.2(@types/[email protected])
'@types/node': 20.12.2
supports-color: 8.1.1
- dev: false
resolution: {integrity: sha512-J7H768dgcpG60d7skZ5uSSwyCZs/S2HrWP1Ds8d1qYAyaaeJmpmmLr9BVw97RjFzmQPOYnoXcKA4GkqDCkduQg==}
dependencies:
'@rushstack/terminal': 0.10.0(@types/[email protected])
- '@types/argparse': 1.0.38
- argparse: 1.0.10
+ '@types/argparse': r2.cnpmjs.org/@types/[email protected]
+ argparse: r2.cnpmjs.org/[email protected]
string-argv: 0.3.2
transitivePeerDependencies:
- '@types/node'
- dev: false
/@sinclair/[email protected]:
resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==}
@@ -4132,7 +4271,7 @@ packages:
resolution: {integrity: sha512-iUL89OJQse9DlZkwY8jhyl12L/qziUkwbdSgQJxRIEceW6vrHAmc5VGwneS7N3pBuiOIKQQmMhAQ660JXHM7eQ==}
dependencies:
'@storybook/blocks': 8.0.5(@types/[email protected])([email protected])([email protected])
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
ts-dedent: 2.2.0
transitivePeerDependencies:
- '@types/react'
@@ -4514,7 +4653,7 @@ packages:
cross-spawn: 7.0.3
esbuild: 0.20.2
esbuild-register: 3.5.0([email protected])
- execa: 5.1.1
+ execa: r2.cnpmjs.org/[email protected]
file-system-cache: 2.3.0
find-cache-dir: 3.3.2
find-up: 5.0.0
@@ -4574,7 +4713,7 @@ packages:
fs-extra: 11.2.0
globby: 11.1.0
ip: 2.0.1
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
open: 8.4.2
pretty-hrtime: 1.0.3
prompts: 2.4.2
@@ -4651,7 +4790,7 @@ packages:
'@types/doctrine': 0.0.3
assert: 2.1.0
doctrine: 3.0.0
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
transitivePeerDependencies:
- encoding
- supports-color
@@ -4695,7 +4834,7 @@ packages:
'@storybook/theming': 8.0.5([email protected])([email protected])
'@storybook/types': 8.0.5
dequal: 2.0.3
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
memoizerific: 1.11.3
store2: 2.14.3
telejson: 7.2.0
@@ -4761,7 +4900,7 @@ packages:
'@storybook/types': 8.0.5
'@types/qs': 6.9.14
dequal: 2.0.3
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
memoizerific: 1.11.3
qs: 6.12.0
tiny-invariant: 1.3.3
@@ -5043,6 +5182,7 @@ packages:
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
dev: false
optional: true
@@ -5052,6 +5192,7 @@ packages:
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
+ libc: [musl]
requiresBuild: true
dev: false
optional: true
@@ -5061,6 +5202,7 @@ packages:
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
+ libc: [glibc]
requiresBuild: true
dev: false
optional: true
@@ -5070,6 +5212,7 @@ packages:
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
+ libc: [musl]
requiresBuild: true
dev: false
optional: true
@@ -5237,10 +5380,6 @@ packages:
resolution: {integrity: sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==}
dev: true
- resolution: {integrity: sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==}
- dev: false
-
resolution: {integrity: sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==}
@@ -5828,7 +5967,6 @@ packages:
vitest: 1.4.0(@types/[email protected])([email protected])
transitivePeerDependencies:
- supports-color
- dev: false
resolution: {integrity: sha512-xofQFwIzfdmLLlHa6ag0dPV8YsnKOCP1KdAeVVh34vSjN2dcUiXYCD9htu/9eM7t8Xln4v03U9HLxLpPlsXdZw==}
@@ -5891,20 +6029,17 @@ packages:
resolution: {integrity: sha512-dOcNn3i9GgZAcJt43wuaEykSluAuOkQgzni1cuxLxTV0nJKanQztp7FxyswdRILaKH+P2XZMPRp2S4MV/pElCw==}
dependencies:
'@volar/source-map': 1.11.1
- dev: false
resolution: {integrity: sha512-hJnOnwZ4+WT5iupLRnuzbULZ42L7BWWPMmruzwtLhJfpDVoZLjNBxHDi2sY2bgZXCKlpU5XcsMFoYrsQmPhfZg==}
dependencies:
muggle-string: 0.3.1
- dev: false
resolution: {integrity: sha512-iU+t2mas/4lYierSnoFOeRFQUhAEMgsFuQxoxvwn5EdQopw43j+J27a4lt9LMInx1gLJBC6qL14WYGlgymaSMQ==}
dependencies:
'@volar/language-core': 1.11.1
path-browserify: 1.0.1
- dev: false
resolution: {integrity: sha512-MjXawxZf2SbZszLPYxaFCjxfibYrzr3eYbKxwpLR9EQN+oaziSu3qKVbwBERj1IFIB8OLUewxB5m/BFzi613og==}
@@ -5958,7 +6093,6 @@ packages:
path-browserify: 1.0.1
typescript: 5.4.3
vue-template-compiler: 2.7.16
- dev: false
resolution: {integrity: sha512-UhenImdc0L0/4ahGCyEzc/pZNwVgcglGy9HVzJ1Bq2Mm9qXOpP8RyNTjookw/gOCUlXSEtuZ2fUg5nrHcoqJcw==}
@@ -6323,12 +6457,6 @@ packages:
engines: {node: '>=14'}
dev: true
- resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==}
- dependencies:
- sprintf-js: 1.0.3
- dev: false
-
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
@@ -6593,11 +6721,11 @@ packages:
dependencies:
bytes: 3.1.2
content-type: 1.0.5
- debug: 2.6.9
+ debug: r2.cnpmjs.org/[email protected]
depd: 2.0.0
destroy: 1.2.0
http-errors: 2.0.0
- iconv-lite: 0.4.24
+ iconv-lite: r2.cnpmjs.org/[email protected]
on-finished: 2.4.1
qs: 6.11.0
raw-body: 2.5.2
@@ -6899,7 +7027,7 @@ packages:
resolution: {integrity: sha512-D5J+kHaVb/wKSFcyyV75uCn8fiY4sV38XJoe4CUyGQ+mOU/fMVYUdH1hJC+CJQ5uY3EnW27SbJYS4X8BiLrAFg==}
engines: {node: '>= 10.0'}
dependencies:
- source-map: 0.6.1
+ source-map: r2.cnpmjs.org/[email protected]
dev: false
@@ -6939,7 +7067,7 @@ packages:
resolution: {integrity: sha512-Lm3L0p+/npIQWNIiyF/nAn7T5dnOwR3xNTHXYEBFBFVPXzCVNZ5lqEC/1eo/EVfpDsQ1I+TX4ORPQgp+UI0CRw==}
engines: {node: 10.* || >= 12.*}
dependencies:
- string-width: 4.2.3
+ string-width: r2.cnpmjs.org/[email protected]
optionalDependencies:
'@colors/colors': 1.5.0
dev: false
@@ -7015,7 +7143,7 @@ packages:
resolution: {integrity: sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==}
engines: {node: '>=12.5.0'}
dependencies:
- color-convert: 2.0.1
+ color-convert: r2.cnpmjs.org/[email protected]
color-string: 1.9.1
dev: true
@@ -7052,7 +7180,6 @@ packages:
resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==}
engines: {node: ^12.20.0 || >=14}
requiresBuild: true
- dev: false
optional: true
@@ -7084,7 +7211,7 @@ packages:
accepts: 1.3.8
bytes: 3.0.0
compressible: 2.0.18
- debug: 2.6.9
+ debug: r2.cnpmjs.org/[email protected]
on-headers: 1.0.2
safe-buffer: 5.1.2
vary: 1.1.2
@@ -7094,7 +7221,6 @@ packages:
resolution: {integrity: sha512-7CEBgcMjVmitjYo5q8JTJVra6X5mQ20uTThdK+0kR7UEaDrAWEQcRiBtWJzga4eRpP6afNwwLsX2SET2JhVB1Q==}
- dev: false
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
@@ -7294,7 +7420,7 @@ packages:
resolution: {integrity: sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==}
dependencies:
- is-what: 3.14.1
+ is-what: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-Dk997v9ZCt3X/npqzyGdTlq6t7lDBhZwGvV94PKzDArjp7BTRm7WlDAXYd/OWdeFHO8OChQYRJNJvUCqCbrtKA==}
@@ -7482,29 +7608,6 @@ packages:
resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==}
- dev: false
-
- resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
- peerDependencies:
- supports-color: '*'
- peerDependenciesMeta:
- supports-color:
- optional: true
- dependencies:
- ms: 2.0.0
- dev: false
-
- resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
- peerDependencies:
- supports-color: '*'
- peerDependenciesMeta:
- supports-color:
- optional: true
- dependencies:
- ms: 2.1.3
- dev: true
resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
@@ -7698,7 +7801,7 @@ packages:
resolution: {integrity: sha512-j/lJHyoLlWi6G1LDdLgvUtz60Zo5GEj+sVYtTVXnYLDPuzgC3llMxonXym9zIwhhUII8vjdw0LXxavpLqTbl1A==}
engines: {node: '>=12'}
dependencies:
- execa: 5.1.1
+ execa: r2.cnpmjs.org/[email protected]
dev: false
@@ -7775,7 +7878,7 @@ packages:
dependencies:
domelementtype: 2.3.0
domhandler: 4.3.1
- entities: 2.2.0
+ entities: r2.cnpmjs.org/[email protected]
dev: false
@@ -7894,10 +7997,6 @@ packages:
resolution: {integrity: sha512-VWU0/zXzVbeJNXvME/5EmLuEj2TauvoaTz6aFYK1Z92JCBlDlZ3Gu0tuGR42kpW1754ywTs+QB0g5TP0oj9Zaw==}
dev: true
- resolution: {integrity: sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==}
- dev: false
-
resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==}
engines: {node: '>=0.12'}
@@ -7913,14 +8012,6 @@ packages:
hasBin: true
dev: false
- resolution: {integrity: sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==}
- hasBin: true
- requiresBuild: true
- dependencies:
- prr: 1.0.1
- optional: true
-
resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==}
dependencies:
@@ -8399,7 +8490,7 @@ packages:
estraverse: 5.3.0
esutils: 2.0.3
optionalDependencies:
- source-map: 0.6.1
+ source-map: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-dc6Y8tzEcSYZMHa+CMPLi/hyo1FzNeonbhJL7Ol0ccuKQkwopJcJBA9YL/xmMTLU1eKigXo9vj9nALElWYSowg==}
@@ -8436,7 +8527,7 @@ packages:
resolution: {integrity: sha512-WFj2isz22JahUv+B788TlO3N6zL3nNJGU8CcZbPZvVEkBPaJdCV4vy5wyghty5ROFbCRnm132v8BScu5/1BQ8g==}
dependencies:
- debug: 3.2.7
+ debug: r2.cnpmjs.org/[email protected]
is-core-module: 2.13.1
resolve: 1.22.8
transitivePeerDependencies:
@@ -8965,7 +9056,7 @@ packages:
content-type: 1.0.5
cookie: 0.6.0
cookie-signature: 1.0.6
- debug: 2.6.9
+ debug: r2.cnpmjs.org/[email protected]
depd: 2.0.0
encodeurl: 1.0.2
escape-html: 1.0.3
@@ -9090,7 +9181,7 @@ packages:
resolution: {integrity: sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==}
engines: {node: '>= 0.8'}
dependencies:
- debug: 2.6.9
+ debug: r2.cnpmjs.org/[email protected]
encodeurl: 1.0.2
escape-html: 1.0.3
on-finished: 2.4.1
@@ -9106,7 +9197,7 @@ packages:
engines: {node: '>=6'}
dependencies:
commondir: 1.0.1
- make-dir: 2.1.0
+ make-dir: r2.cnpmjs.org/[email protected]
pkg-dir: 3.0.0
dev: false
@@ -9115,7 +9206,7 @@ packages:
engines: {node: '>=8'}
dependencies:
commondir: 1.0.1
- make-dir: 3.1.0
+ make-dir: r2.cnpmjs.org/[email protected]
pkg-dir: 4.2.0
@@ -9266,15 +9357,6 @@ packages:
jsonfile: 6.1.0
universalify: 2.0.1
- resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==}
- engines: {node: '>=6 <7 || >=8'}
- dependencies:
- graceful-fs: 4.2.11
- jsonfile: 4.0.0
- universalify: 0.1.2
- dev: false
-
resolution: {integrity: sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==}
engines: {node: '>= 8'}
@@ -9289,16 +9371,8 @@ packages:
resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==}
- resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
- engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
- os: [darwin]
- requiresBuild: true
- dev: true
- optional: true
-
- resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
+ resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
requiresBuild: true
@@ -9618,7 +9692,6 @@ packages:
entities: 4.5.0
webidl-conversions: 7.0.0
whatwg-mimetype: 3.0.0
- dev: false
resolution: {integrity: sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==}
@@ -9677,7 +9750,6 @@ packages:
resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==}
hasBin: true
- dev: false
resolution: {integrity: sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==}
@@ -9708,7 +9780,6 @@ packages:
resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==}
- dev: false
resolution: {integrity: sha512-YXxSlJBZTP7RS3tWnQw74ooKa6L9b9i9QYXY21eUEvhZ3u9XLfv6OnFsQq6RxkhHygsaUMvYsZRV5rU/OVNZxw==}
@@ -9742,7 +9813,7 @@ packages:
dependencies:
'@types/html-minifier-terser': 6.1.0
html-minifier-terser: 6.1.0
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
pretty-error: 4.0.0
tapable: 2.2.1
webpack: 5.91.0(@swc/[email protected])([email protected])
@@ -9754,7 +9825,7 @@ packages:
domelementtype: 2.3.0
domhandler: 4.3.1
domutils: 2.8.0
- entities: 2.2.0
+ entities: r2.cnpmjs.org/[email protected]
dev: false
@@ -9819,6 +9890,7 @@ packages:
engines: {node: '>=0.10.0'}
dependencies:
safer-buffer: 2.1.2
+ dev: true
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
@@ -9826,6 +9898,7 @@ packages:
requiresBuild: true
dependencies:
safer-buffer: 2.1.2
+ dev: true
resolution: {integrity: sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==}
@@ -9842,13 +9915,6 @@ packages:
resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==}
engines: {node: '>= 4'}
- resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==}
- engines: {node: '>=0.10.0'}
- hasBin: true
- requiresBuild: true
- optional: true
-
resolution: {integrity: sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==}
dev: false
@@ -9871,6 +9937,7 @@ packages:
resolution: {integrity: sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==}
engines: {node: '>=8'}
+ dev: true
resolution: {integrity: sha512-okYUR7ZQPH+efeuMJGlq4f8ubUgO50kByRPyt/Cy1Io4PSRsPjxME+YlVaCOx+NIToW7hCsZNFJyTPFFKepRSA==}
@@ -10304,9 +10371,6 @@ packages:
call-bind: 1.0.7
get-intrinsic: 1.2.4
- resolution: {integrity: sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==}
-
resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==}
engines: {node: '>=8'}
@@ -10350,7 +10414,6 @@ packages:
resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==}
engines: {node: '>=8'}
- dev: false
resolution: {integrity: sha512-1WUsZ9R1lA0HtBSohTkm39WTPlNKSJ5iFk7UwqXkBLoHQT+hfqPsfsTDVuZdKGaBwn7din9bS7SsnoAr943hvw==}
@@ -10363,7 +10426,6 @@ packages:
semver: 7.6.0
transitivePeerDependencies:
- supports-color
- dev: false
resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==}
@@ -10372,7 +10434,6 @@ packages:
istanbul-lib-coverage: 3.2.2
make-dir: 4.0.0
supports-color: 7.2.0
- dev: false
resolution: {integrity: sha512-wHOoEsNJTVltaJp8eVkm8w+GVkVNHT2YDYo53YdzQEL2gWm1hBX5cGFR9hQJtuGLebidVX7et3+dmDZrmclduw==}
@@ -10383,7 +10444,6 @@ packages:
istanbul-lib-coverage: 3.2.2
transitivePeerDependencies:
- supports-color
- dev: false
resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==}
@@ -10391,7 +10451,6 @@ packages:
dependencies:
html-escaper: 2.0.2
istanbul-lib-report: 3.0.1
- dev: false
resolution: {integrity: sha512-t91HubM4ZDQ70M9wqp+pcNpu8OyJ9UAtXntT/Bcsvp5tZMnz9vRa+IunKXeI8AnfZMTv0jNuVEmGeLSMjVvfPw==}
@@ -10454,10 +10513,6 @@ packages:
hasBin: true
dev: true
- resolution: {integrity: sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==}
- dev: false
-
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
@@ -10606,12 +10661,6 @@ packages:
resolution: {integrity: sha512-AilxAyFOAcK5wA1+LeaySVBrHsGQvUFCDWXKpZjzaL0PqW+xfBOttn8GNtWKFWqneyMZj41MWF9Kl6iPWLwgOA==}
- resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==}
- optionalDependencies:
- graceful-fs: 4.2.11
- dev: false
-
resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==}
dependencies:
@@ -10651,7 +10700,6 @@ packages:
resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==}
- dev: false
resolution: {integrity: sha512-KvNT4XqAMzdcL6ka6Tl3i2lYeFDgXNCuIX+xNx6ZMVR1dFq+idXd9FLKNMOIx0t9mJ9/HudyX4oZWXZQ0UJHeg==}
@@ -10691,16 +10739,16 @@ packages:
hasBin: true
dependencies:
copy-anything: 2.0.6
- parse-node-version: 1.0.1
+ parse-node-version: r2.cnpmjs.org/[email protected]
tslib: 2.6.2
optionalDependencies:
- errno: 0.1.8
+ errno: r2.cnpmjs.org/[email protected]
graceful-fs: 4.2.11
- image-size: 0.5.5
- make-dir: 2.1.0
- mime: 1.6.0
+ image-size: r2.cnpmjs.org/[email protected]
+ make-dir: r2.cnpmjs.org/[email protected]
+ mime: r2.cnpmjs.org/[email protected]
needle: 3.3.1
- source-map: 0.6.1
+ source-map: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==}
@@ -10823,6 +10871,7 @@ packages:
resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==}
+ dev: true
resolution: {integrity: sha512-kZzYOKspf8XVX5AvmQF94gQW0lejFVgb80G85bU4ZWzoJ6C03PQg3coYAUpSTpQWelrZELd3XWgHzw4Ck5kaIw==}
@@ -10836,14 +10885,6 @@ packages:
resolution: {integrity: sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==}
dev: true
- resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==}
- dev: false
-
- resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==}
- dev: false
-
resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==}
dev: true
@@ -10971,6 +11012,12 @@ packages:
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: true
+ resolution: {integrity: sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==}
+ dependencies:
+ sourcemap-codec: r2.cnpmjs.org/[email protected]
+ dev: true
+
resolution: {integrity: sha512-ISQTe55T2ao7XtlAStud6qwYPZjE4GK1S/BeVPus4jrq6JuOnQ00YKQC581RWhR122W7msZV263KzVeLoqidyQ==}
engines: {node: '>=12'}
@@ -10983,28 +11030,12 @@ packages:
'@babel/parser': 7.24.1
'@babel/types': 7.24.0
source-map-js: 1.2.0
- dev: false
-
- resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==}
- engines: {node: '>=6'}
- requiresBuild: true
- dependencies:
- pify: 4.0.1
- semver: 5.7.2
-
- resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==}
- engines: {node: '>=8'}
- dependencies:
- semver: 6.3.1
resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==}
engines: {node: '>=10'}
dependencies:
semver: 7.6.0
- dev: false
resolution: {integrity: sha512-0aF7ZmVon1igznGI4VS30yugpduQW3y3GkcgGJOp7d8x8QrizhigUxjI/m2UojsXXto+jLAH3KSz+xOJTiORjg==}
@@ -11106,12 +11137,6 @@ packages:
dependencies:
mime-db: 1.52.0
- resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==}
- engines: {node: '>=4'}
- hasBin: true
- requiresBuild: true
-
resolution: {integrity: sha512-5lZ5tyrIfliMXzFtkYyekWbtRXObT9OWa8IwQ5uxTBDHucNNwniRqo0yInflj+iYi5CBa6qxadGzGarDfuEOxA==}
engines: {node: '>=16'}
@@ -11142,8 +11167,7 @@ packages:
resolution: {integrity: sha512-6FsRAQsxQ61mw+qP1ZzbL9Bc78x2p5OqNgNpnoAFLTrX8n5Kxph0CsnhmKKNXTWjXqU5L0pGPR7hYk+XWZr60Q==}
dependencies:
- brace-expansion: 1.1.11
- dev: false
+ brace-expansion: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
@@ -11232,10 +11256,10 @@ packages:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
+ dev: false
resolution: {integrity: sha512-ckmWDJjphvd/FvZawgygcUeQCxzvohjFO5RxTjj4eq8kw359gFF3E1brjfI+viLMxss5JrHTDRHZvu2/tuy0Qg==}
- dev: false
resolution: {integrity: sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==}
@@ -11266,7 +11290,7 @@ packages:
hasBin: true
requiresBuild: true
dependencies:
- iconv-lite: 0.6.3
+ iconv-lite: r2.cnpmjs.org/[email protected]
sax: 1.3.0
optional: true
@@ -11734,10 +11758,6 @@ packages:
type-fest: 3.13.1
dev: true
- resolution: {integrity: sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==}
- engines: {node: '>= 0.10'}
-
resolution: {integrity: sha512-Euf9GG8WT9CdqwuWJGdf3RkUcTBArppHABkO7Lm8IzRQp0e2r/kkFnmhu4TSK30Wcu5rVAZLmfPKSBBi9tWFog==}
dependencies:
@@ -11770,7 +11790,6 @@ packages:
resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==}
- dev: false
resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==}
@@ -11865,11 +11884,6 @@ packages:
hasBin: true
dev: true
- resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==}
- engines: {node: '>=6'}
- requiresBuild: true
-
resolution: {integrity: sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==}
engines: {node: '>= 6'}
@@ -11914,7 +11928,7 @@ packages:
dependencies:
playwright-core: 1.42.1
optionalDependencies:
- fsevents: 2.3.2
+ fsevents: r2.cnpmjs.org/[email protected]
dev: true
@@ -12001,7 +12015,7 @@ packages:
engines: {node: ^10 || ^12 || >=14}
dependencies:
nanoid: 3.3.7
- picocolors: 1.0.0
+ picocolors: r2.cnpmjs.org/[email protected]
source-map-js: 1.2.0
@@ -12023,7 +12037,7 @@ packages:
resolution: {integrity: sha512-AoJ5YMAcXKYxKhuJGdcvse+Voc6v1RgnsR3nWcYU7q4t6z0Q6T86sv5Zq8VIRbOWWFpvdGE83LtdSMNd+6Y0xw==}
dependencies:
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
renderkid: 3.0.0
dev: false
@@ -12079,7 +12093,7 @@ packages:
resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==}
dependencies:
- loose-envify: 1.4.0
+ loose-envify: r2.cnpmjs.org/[email protected]
object-assign: 4.1.1
react-is: 16.13.1
@@ -12092,16 +12106,16 @@ packages:
engines: {node: '>=12.0.0'}
requiresBuild: true
dependencies:
- '@protobufjs/aspromise': 1.1.2
- '@protobufjs/base64': 1.1.2
- '@protobufjs/codegen': 2.0.4
- '@protobufjs/eventemitter': 1.1.0
- '@protobufjs/fetch': 1.1.0
- '@protobufjs/float': 1.0.2
- '@protobufjs/inquire': 1.1.0
- '@protobufjs/path': 1.1.2
- '@protobufjs/pool': 1.1.0
- '@protobufjs/utf8': 1.1.0
+ '@protobufjs/aspromise': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/base64': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/codegen': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/eventemitter': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/fetch': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/float': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/inquire': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/path': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/pool': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/utf8': r2.cnpmjs.org/@protobufjs/[email protected]
'@types/node': 20.12.2
long: 5.2.3
dev: false
@@ -12138,11 +12152,6 @@ packages:
resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
dev: true
- resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==}
- requiresBuild: true
- optional: true
-
resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==}
dev: true
@@ -12229,7 +12238,7 @@ packages:
dependencies:
bytes: 3.1.2
http-errors: 2.0.0
- iconv-lite: 0.4.24
+ iconv-lite: r2.cnpmjs.org/[email protected]
unpipe: 1.0.0
dev: false
@@ -12600,10 +12609,24 @@ packages:
peerDependencies:
react: ^18.2.0
dependencies:
- loose-envify: 1.4.0
+ loose-envify: r2.cnpmjs.org/[email protected]
react: 18.2.0
scheduler: 0.23.0
+ resolution: {integrity: sha512-3UG1cVNWdQHsqcqtuLRAtkkOkvB8seF8cY/IZQJbcyqT1Fbv7Hk8KwatAg6Ud1dWGbvrDuT9M+fkCyD3P+WHlw==}
+ peerDependencies:
+ react: ^16.6.0 || ^17.0.0
+ dependencies:
+ '@babel/runtime': 7.24.1
+ '@types/prop-types': 15.7.12
+ immutability-helper: r2.cnpmjs.org/[email protected]
+ prop-types: 15.8.1
+ react: 18.2.0
+ react-motion: r2.cnpmjs.org/[email protected]([email protected])
+ react-multi-ref: 1.0.1
+ dev: false
+
resolution: {integrity: sha512-LtY5Xw1zTPqHkVmtM3X8MUOxNDOUhv/khTgBgrUvwaS064bwVvxT+q5El0uUFNx5IEPKXuRejr7UqLwBIg5pdw==}
peerDependencies:
@@ -12690,6 +12713,12 @@ packages:
- react-dom
dev: false
+ resolution: {integrity: sha512-zgQKmduv95vtXIkze6583pRW7Y+mNj7R0bYgxIRWOrsEfxBQaK+MZ6yjTiZ/qcFV4bYGM74nE9isb+YRBNIw2g==}
+ dependencies:
+ '@babel/runtime': 7.24.1
+ dev: false
+
resolution: {integrity: sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==}
engines: {node: '>=0.10.0'}
@@ -12724,7 +12753,7 @@ packages:
resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}
engines: {node: '>=0.10.0'}
dependencies:
- loose-envify: 1.4.0
+ loose-envify: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-aNtBq4jR8NawpKJQldrQcSW9y/d+KWH4v24HWkHljOZ7H0av+YTGANBzRh9A5pw7v/bLVsLVPpOhJ7gHNVy8lA==}
@@ -12794,7 +12823,7 @@ packages:
dependencies:
ast-types: 0.16.1
esprima: 4.0.1
- source-map: 0.6.1
+ source-map: r2.cnpmjs.org/[email protected]
tiny-invariant: 1.3.3
tslib: 2.6.2
@@ -12982,7 +13011,7 @@ packages:
css-select: 4.3.0
dom-converter: 0.2.0
htmlparser2: 6.1.0
- lodash: 4.17.21
+ lodash: r2.cnpmjs.org/[email protected]
strip-ansi: 6.0.1
dev: false
@@ -13026,13 +13055,6 @@ packages:
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
dev: true
- resolution: {integrity: sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==}
- dependencies:
- is-core-module: 2.13.1
- path-parse: 1.0.7
- dev: false
-
resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==}
hasBin: true
@@ -13242,20 +13264,19 @@ packages:
hasBin: true
dependencies:
lru-cache: 6.0.0
- dev: false
resolution: {integrity: sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==}
engines: {node: '>=10'}
hasBin: true
dependencies:
- lru-cache: 6.0.0
+ lru-cache: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==}
engines: {node: '>= 0.8.0'}
dependencies:
- debug: 2.6.9
+ debug: r2.cnpmjs.org/[email protected]
depd: 2.0.0
destroy: 1.2.0
encodeurl: 1.0.2
@@ -13263,7 +13284,7 @@ packages:
etag: 1.8.1
fresh: 0.5.2
http-errors: 2.0.0
- mime: 1.6.0
+ mime: r2.cnpmjs.org/[email protected]
ms: 2.1.3
on-finished: 2.4.1
range-parser: 1.2.1
@@ -13456,7 +13477,7 @@ packages:
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
dependencies:
buffer-from: 1.1.2
- source-map: 0.6.1
+ source-map: r2.cnpmjs.org/[email protected]
dev: false
@@ -13497,10 +13518,6 @@ packages:
engines: {node: '>= 10.x'}
dev: true
- resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==}
- dev: false
-
resolution: {integrity: sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==}
dev: true
@@ -13736,7 +13753,6 @@ packages:
engines: {node: '>=10'}
dependencies:
has-flag: 4.0.0
- dev: false
resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==}
@@ -13889,7 +13905,6 @@ packages:
'@istanbuljs/schema': 0.1.3
glob: 7.2.3
minimatch: 3.1.2
- dev: false
resolution: {integrity: sha512-te/NtwBwfiNRLf9Ijqx3T0nlqZiQ2XrrtBvu+cLL8ZRrGkO0NHTug8MYFKyoSrv/sHTaSKfilUkizV6XhxMJ3g==}
@@ -14213,7 +14228,6 @@ packages:
resolution: {integrity: sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==}
engines: {node: '>=14.17'}
hasBin: true
- dev: false
resolution: {integrity: sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==}
@@ -14328,11 +14342,6 @@ packages:
resolution: {integrity: sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==}
dev: true
- resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==}
- engines: {node: '>= 4.0.0'}
- dev: false
-
resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==}
engines: {node: '>= 4.0.0'}
@@ -14370,7 +14379,7 @@ packages:
dependencies:
browserslist: 4.23.0
escalade: 3.1.2
- picocolors: 1.0.0
+ picocolors: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-Hv25Bh+eAbOLlsjJreVPOs4vd51rrtCrmhyOJtbpAojro34jS4KQaEp4/EvlHJX7jSO42VvEFpkastVyXyIsdQ==}
@@ -14460,14 +14469,13 @@ packages:
resolution: {integrity: sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==}
engines: {node: '>= 0.10'}
- dev: false
resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==}
engines: {node: '>= 0.8'}
dev: false
resolution: {integrity: sha512-VZDAseqjrHgNd4Kh8icYHWzTKSCZMhia7GyHfhtzLW33fZlG9SwsB6CEhgyVOWkJfJ2pFLrp/Gj1FSfAiqH9Lw==}
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
@@ -14487,6 +14495,27 @@ packages:
- supports-color
- terser
+ resolution: {integrity: sha512-VZDAseqjrHgNd4Kh8icYHWzTKSCZMhia7GyHfhtzLW33fZlG9SwsB6CEhgyVOWkJfJ2pFLrp/Gj1FSfAiqH9Lw==}
+ engines: {node: ^18.0.0 || >=20.0.0}
+ hasBin: true
+ dependencies:
+ cac: 6.7.14
+ debug: 4.3.4
+ pathe: 1.1.2
+ picocolors: r2.cnpmjs.org/[email protected]
+ vite: 5.2.7(@types/[email protected])([email protected])
+ transitivePeerDependencies:
+ - '@types/node'
+ - less
+ - lightningcss
+ - sass
+ - stylus
+ - sugarss
+ - supports-color
+ - terser
+ dev: true
+
resolution: {integrity: sha512-zEYyQxH7lKto1VTKZHF3ZZeOPkkJgnMrePY4VxDHfDSvDjmYMMfWjZxYmNwW8QxbaItWJQhhXY+geAbyNphI7g==}
engines: {node: ^14.18.0 || >=16.0.0}
@@ -14510,7 +14539,19 @@ packages:
- '@types/node'
- rollup
- supports-color
- dev: false
+
+ resolution: {integrity: sha512-R5oVY8xDJjLXLTs2XDYzvYbc/RTZuIwOx2xcFbYf+/VXB6eJuatDgt8jzQ7kZ+IrgwQhe6tU8U2fTyy72C25CQ==}
+ engines: {node: ^14.18.0 || >=16.0.0}
+ peerDependencies:
+ vite: '>=2.0.0'
+ dependencies:
+ acorn: 8.11.3
+ es-module-lexer: r2.cnpmjs.org/[email protected]
+ fs-extra: 10.1.0
+ magic-string: 0.25.9
+ vite: 5.2.7(@types/[email protected])([email protected])
+ dev: true
resolution: {integrity: sha512-k14PWOKLI6pMaSzAuGtT+Cf0YmIx12z9YGon39onaJNy8DLBfBJrzg9FQEmkAM5lpHBZs9wksWAsyF/HkpEwJA==}
@@ -14602,7 +14643,7 @@ packages:
tinybench: 2.6.0
tinypool: 0.8.3
- vite-node: 1.4.0(@types/[email protected])([email protected])
+ vite-node: 1.4.0(@types/[email protected])
why-is-node-running: 2.2.2
transitivePeerDependencies:
- less
@@ -14612,9 +14653,8 @@ packages:
- sugarss
- supports-color
- terser
- dev: false
resolution: {integrity: sha512-gujzn0g7fmwf83/WzrDTnncZt2UiXP41mHuFYFrdwaLRVQ6JYQEiME2IfEjU3vcFL3VKa75XhI3lFgn+hfVsQw==}
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
@@ -14649,7 +14689,7 @@ packages:
chai: 4.4.1
debug: 4.3.4
execa: 8.0.1
- jsdom: 24.0.0
+ happy-dom: 13.3.8
local-pkg: 0.5.0
magic-string: 0.30.8
pathe: 1.1.2
@@ -14671,7 +14711,7 @@ packages:
- terser
dev: true
resolution: {integrity: sha512-gujzn0g7fmwf83/WzrDTnncZt2UiXP41mHuFYFrdwaLRVQ6JYQEiME2IfEjU3vcFL3VKa75XhI3lFgn+hfVsQw==}
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
@@ -14706,6 +14746,7 @@ packages:
chai: 4.4.1
debug: 4.3.4
execa: 8.0.1
+ jsdom: 24.0.0
local-pkg: 0.5.0
magic-string: 0.30.8
pathe: 1.1.2
@@ -14715,7 +14756,7 @@ packages:
tinybench: 2.6.0
tinypool: 0.8.3
- vite-node: 1.4.0(@types/[email protected])([email protected])
+ vite-node: 1.4.0(@types/[email protected])
why-is-node-running: 2.2.2
transitivePeerDependencies:
- less
@@ -14750,7 +14791,6 @@ packages:
dependencies:
de-indent: 1.0.2
he: 1.2.0
- dev: false
resolution: {integrity: sha512-WesKCAZCRAbmmhuGl3+VrdWItEvfoFIPXOvUJkjULi+x+6G/Dy69yO3TBRJDr9eUlmsNAwVmxsNZxvHKzbkKdg==}
@@ -14762,7 +14802,6 @@ packages:
'@vue/language-core': 1.8.27([email protected])
semver: 7.6.0
typescript: 5.4.3
- dev: false
resolution: {integrity: sha512-5hjyV/jLEIKD/jYl4cavMcnzKwjMKohureP8ejn3hhEjwhWIhWeuzL2kJAjzl/WyVsgPY56Sy4Z40C3lVshxXA==}
@@ -14814,9 +14853,6 @@ packages:
engines: {node: '>= 8'}
dev: true
- resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
-
resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==}
engines: {node: '>=12'}
@@ -14909,7 +14945,6 @@ packages:
resolution: {integrity: sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==}
engines: {node: '>=12'}
- dev: false
resolution: {integrity: sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==}
@@ -14928,7 +14963,7 @@ packages:
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
dependencies:
tr46: 0.0.3
- webidl-conversions: 3.0.1
+ webidl-conversions: r2.cnpmjs.org/[email protected]
resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==}
@@ -15166,9 +15201,535 @@ packages:
engines: {node: '>=8.0.0'}
hasBin: true
dependencies:
- lodash.get: 4.4.2
- lodash.isequal: 4.5.0
+ lodash.get: r2.cnpmjs.org/[email protected]
+ lodash.isequal: r2.cnpmjs.org/[email protected]
validator: 13.11.0
optionalDependencies:
commander: 9.5.0
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==, tarball: https://r2.cnpmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz}
+ name: '@protobufjs/aspromise'
+ version: 1.1.2
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==, tarball: https://r2.cnpmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz}
+ name: '@protobufjs/base64'
+ version: 1.1.2
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==, tarball: https://r2.cnpmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz}
+ name: '@protobufjs/codegen'
+ version: 2.0.4
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==, tarball: https://r2.cnpmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz}
+ name: '@protobufjs/eventemitter'
+ version: 1.1.0
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==, tarball: https://r2.cnpmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz}
+ name: '@protobufjs/fetch'
+ version: 1.1.0
+ dependencies:
+ '@protobufjs/aspromise': r2.cnpmjs.org/@protobufjs/[email protected]
+ '@protobufjs/inquire': r2.cnpmjs.org/@protobufjs/[email protected]
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==, tarball: https://r2.cnpmjs.org/@protobufjs/float/-/float-1.0.2.tgz}
+ name: '@protobufjs/float'
+ version: 1.0.2
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==, tarball: https://r2.cnpmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz}
+ name: '@protobufjs/inquire'
+ version: 1.1.0
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==, tarball: https://r2.cnpmjs.org/@protobufjs/path/-/path-1.1.2.tgz}
+ name: '@protobufjs/path'
+ version: 1.1.2
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==, tarball: https://r2.cnpmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz}
+ name: '@protobufjs/pool'
+ version: 1.1.0
+ dev: false
+
+ r2.cnpmjs.org/@protobufjs/[email protected]:
+ resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==, tarball: https://r2.cnpmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz}
+ name: '@protobufjs/utf8'
+ version: 1.1.0
+ dev: false
+
+ r2.cnpmjs.org/@types/[email protected]:
+ resolution: {integrity: sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==, tarball: https://r2.cnpmjs.org/@types/argparse/-/argparse-1.0.38.tgz}
+ name: '@types/argparse'
+ version: 1.0.38
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==, tarball: https://r2.cnpmjs.org/ajv/-/ajv-6.12.6.tgz}
+ name: ajv
+ version: 6.12.6
+ dependencies:
+ fast-deep-equal: r2.cnpmjs.org/[email protected]
+ fast-json-stable-stringify: r2.cnpmjs.org/[email protected]
+ json-schema-traverse: r2.cnpmjs.org/[email protected]
+ uri-js: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==, tarball: https://r2.cnpmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz}
+ name: ansi-regex
+ version: 5.0.1
+ engines: {node: '>=8'}
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==, tarball: https://r2.cnpmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz}
+ name: ansi-styles
+ version: 4.3.0
+ engines: {node: '>=8'}
+ dependencies:
+ color-convert: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==, tarball: https://r2.cnpmjs.org/argparse/-/argparse-1.0.10.tgz}
+ name: argparse
+ version: 1.0.10
+ dependencies:
+ sprintf-js: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==, tarball: https://r2.cnpmjs.org/balanced-match/-/balanced-match-1.0.2.tgz}
+ name: balanced-match
+ version: 1.0.2
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==, tarball: https://r2.cnpmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz}
+ name: brace-expansion
+ version: 1.1.11
+ dependencies:
+ balanced-match: r2.cnpmjs.org/[email protected]
+ concat-map: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==, tarball: https://r2.cnpmjs.org/color-convert/-/color-convert-2.0.1.tgz}
+ name: color-convert
+ version: 2.0.1
+ engines: {node: '>=7.0.0'}
+ dependencies:
+ color-name: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==, tarball: https://r2.cnpmjs.org/color-name/-/color-name-1.1.4.tgz}
+ name: color-name
+ version: 1.1.4
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==, tarball: https://r2.cnpmjs.org/concat-map/-/concat-map-0.0.1.tgz}
+ name: concat-map
+ version: 0.0.1
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==, tarball: https://r2.cnpmjs.org/debug/-/debug-2.6.9.tgz}
+ name: debug
+ version: 2.6.9
+ peerDependencies:
+ supports-color: '*'
+ peerDependenciesMeta:
+ supports-color:
+ optional: true
+ dependencies:
+ ms: 2.0.0
+ dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==, tarball: https://r2.cnpmjs.org/debug/-/debug-3.2.7.tgz}
+ name: debug
+ version: 3.2.7
+ peerDependencies:
+ supports-color: '*'
+ peerDependenciesMeta:
+ supports-color:
+ optional: true
+ dependencies:
+ ms: r2.cnpmjs.org/[email protected]
+ dev: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==, tarball: https://r2.cnpmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz}
+ name: emoji-regex
+ version: 8.0.0
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==, tarball: https://r2.cnpmjs.org/entities/-/entities-2.2.0.tgz}
+ name: entities
+ version: 2.2.0
+ dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==, tarball: https://r2.cnpmjs.org/errno/-/errno-0.1.8.tgz}
+ name: errno
+ version: 0.1.8
+ hasBin: true
+ requiresBuild: true
+ dependencies:
+ prr: r2.cnpmjs.org/[email protected]
+ optional: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-ooYciCUtfw6/d2w56UVeqHPcoCFAiJdz5XOkYpv/Txl1HMUozpXjz/2RIQgqwKdXNDPSF1W7mJCFse3G+HDyAA==, tarball: https://r2.cnpmjs.org/es-module-lexer/-/es-module-lexer-0.4.1.tgz}
+ name: es-module-lexer
+ version: 0.4.1
+ dev: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==, tarball: https://r2.cnpmjs.org/execa/-/execa-5.1.1.tgz}
+ name: execa
+ version: 5.1.1
+ engines: {node: '>=10'}
+ dependencies:
+ cross-spawn: 7.0.3
+ get-stream: 6.0.1
+ human-signals: 2.1.0
+ is-stream: 2.0.1
+ merge-stream: 2.0.0
+ npm-run-path: 4.0.1
+ onetime: 5.1.2
+ signal-exit: 3.0.7
+ strip-final-newline: 2.0.0
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==, tarball: https://r2.cnpmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz}
+ name: fast-deep-equal
+ version: 3.1.3
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==, tarball: https://r2.cnpmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz}
+ name: fast-json-stable-stringify
+ version: 2.1.0
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==, tarball: https://r2.cnpmjs.org/fs-extra/-/fs-extra-7.0.1.tgz}
+ name: fs-extra
+ version: 7.0.1
+ engines: {node: '>=6 <7 || >=8'}
+ dependencies:
+ graceful-fs: 4.2.11
+ jsonfile: r2.cnpmjs.org/[email protected]
+ universalify: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==, tarball: https://r2.cnpmjs.org/fsevents/-/fsevents-2.3.2.tgz}
+ name: fsevents
+ version: 2.3.2
+ engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
+ os: [darwin]
+ requiresBuild: true
+ dev: true
+ optional: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==, tarball: https://r2.cnpmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz}
+ name: iconv-lite
+ version: 0.4.24
+ engines: {node: '>=0.10.0'}
+ dependencies:
+ safer-buffer: 2.1.2
+ dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==, tarball: https://r2.cnpmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz}
+ name: iconv-lite
+ version: 0.6.3
+ engines: {node: '>=0.10.0'}
+ requiresBuild: true
+ dependencies:
+ safer-buffer: r2.cnpmjs.org/[email protected]
+ optional: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==, tarball: https://r2.cnpmjs.org/image-size/-/image-size-0.5.5.tgz}
+ name: image-size
+ version: 0.5.5
+ engines: {node: '>=0.10.0'}
+ hasBin: true
+ requiresBuild: true
+ optional: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-Q0QaXjPjwIju/28TsugCHNEASwoCcJSyJV3uO1sOIQGI0jKgm9f41Lvz0DZj3n46cNCyAZTsEYoY4C2bVRUzyQ==, tarball: https://r2.cnpmjs.org/immutability-helper/-/immutability-helper-3.1.1.tgz}
+ name: immutability-helper
+ version: 3.1.1
+ dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==, tarball: https://r2.cnpmjs.org/import-lazy/-/import-lazy-4.0.0.tgz}
+ name: import-lazy
+ version: 4.0.0
+ engines: {node: '>=8'}
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==, tarball: https://r2.cnpmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz}
+ name: is-fullwidth-code-point
+ version: 3.0.0
+ engines: {node: '>=8'}
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==, tarball: https://r2.cnpmjs.org/is-what/-/is-what-3.14.1.tgz}
+ name: is-what
+ version: 3.14.1
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==, tarball: https://r2.cnpmjs.org/jju/-/jju-1.4.0.tgz}
+ name: jju
+ version: 1.4.0
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==, tarball: https://r2.cnpmjs.org/js-tokens/-/js-tokens-4.0.0.tgz}
+ name: js-tokens
+ version: 4.0.0
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==, tarball: https://r2.cnpmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz}
+ name: json-schema-traverse
+ version: 0.4.1
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==, tarball: https://r2.cnpmjs.org/jsonfile/-/jsonfile-4.0.0.tgz}
+ name: jsonfile
+ version: 4.0.0
+ optionalDependencies:
+ graceful-fs: 4.2.11
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==, tarball: https://r2.cnpmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz}
+ name: lodash.camelcase
+ version: 4.3.0
+ dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==, tarball: https://r2.cnpmjs.org/lodash.get/-/lodash.get-4.4.2.tgz}
+ name: lodash.get
+ version: 4.4.2
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==, tarball: https://r2.cnpmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz}
+ name: lodash.isequal
+ version: 4.5.0
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==, tarball: https://r2.cnpmjs.org/lodash/-/lodash-4.17.21.tgz}
+ name: lodash
+ version: 4.17.21
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==, tarball: https://r2.cnpmjs.org/loose-envify/-/loose-envify-1.4.0.tgz}
+ name: loose-envify
+ version: 1.4.0
+ hasBin: true
+ dependencies:
+ js-tokens: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==, tarball: https://r2.cnpmjs.org/lru-cache/-/lru-cache-6.0.0.tgz}
+ name: lru-cache
+ version: 6.0.0
+ engines: {node: '>=10'}
+ dependencies:
+ yallist: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==, tarball: https://r2.cnpmjs.org/make-dir/-/make-dir-2.1.0.tgz}
+ name: make-dir
+ version: 2.1.0
+ engines: {node: '>=6'}
+ requiresBuild: true
+ dependencies:
+ pify: r2.cnpmjs.org/[email protected]
+ semver: 5.7.2
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==, tarball: https://r2.cnpmjs.org/make-dir/-/make-dir-3.1.0.tgz}
+ name: make-dir
+ version: 3.1.0
+ engines: {node: '>=8'}
+ dependencies:
+ semver: 6.3.1
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==, tarball: https://r2.cnpmjs.org/mime/-/mime-1.6.0.tgz}
+ name: mime
+ version: 1.6.0
+ engines: {node: '>=4'}
+ hasBin: true
+ requiresBuild: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==, tarball: https://r2.cnpmjs.org/ms/-/ms-2.1.3.tgz}
+ name: ms
+ version: 2.1.3
+ requiresBuild: true
+ dev: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==, tarball: https://r2.cnpmjs.org/parse-node-version/-/parse-node-version-1.0.1.tgz}
+ name: parse-node-version
+ version: 1.0.1
+ engines: {node: '>= 0.10'}
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==, tarball: https://r2.cnpmjs.org/path-parse/-/path-parse-1.0.7.tgz}
+ name: path-parse
+ version: 1.0.7
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-YHk5ez1hmMR5LOkb9iJkLKqoBlL7WD5M8ljC75ZfzXriuBIVNuecaXuU7e+hOwyqf24Wxhh7Vxgt7Hnw9288Tg==, tarball: https://r2.cnpmjs.org/performance-now/-/performance-now-0.2.0.tgz}
+ name: performance-now
+ version: 0.2.0
+ dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==, tarball: https://r2.cnpmjs.org/performance-now/-/performance-now-2.1.0.tgz}
+ name: performance-now
+ version: 2.1.0
+ dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==, tarball: https://r2.cnpmjs.org/picocolors/-/picocolors-1.0.0.tgz}
+ name: picocolors
+ version: 1.0.0
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==, tarball: https://r2.cnpmjs.org/pify/-/pify-4.0.1.tgz}
+ name: pify
+ version: 4.0.1
+ engines: {node: '>=6'}
+ requiresBuild: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==, tarball: https://r2.cnpmjs.org/prr/-/prr-1.0.1.tgz}
+ name: prr
+ version: 1.0.1
+ requiresBuild: true
+ optional: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==, tarball: https://r2.cnpmjs.org/raf/-/raf-3.4.1.tgz}
+ name: raf
+ version: 3.4.1
+ dependencies:
+ performance-now: r2.cnpmjs.org/[email protected]
+ dev: false
+
+ resolution: {integrity: sha512-9q3YAvHoUiWlP3cK0v+w1N5Z23HXMj4IF4YuvjvWegWqNPfLXsOBE/V7UvQGpXxHFKRQQcNcVQE31g9SB/6qgQ==, tarball: https://r2.cnpmjs.org/react-motion/-/react-motion-0.5.2.tgz}
+ id: r2.cnpmjs.org/react-motion/0.5.2
+ name: react-motion
+ version: 0.5.2
+ peerDependencies:
+ react: ^0.14.9 || ^15.3.0 || ^16.0.0
+ dependencies:
+ performance-now: r2.cnpmjs.org/[email protected]
+ prop-types: 15.8.1
+ raf: r2.cnpmjs.org/[email protected]
+ react: 18.2.0
dev: false
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==, tarball: https://r2.cnpmjs.org/resolve/-/resolve-1.19.0.tgz}
+ name: resolve
+ version: 1.19.0
+ dependencies:
+ is-core-module: 2.13.1
+ path-parse: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==, tarball: https://r2.cnpmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz}
+ name: safer-buffer
+ version: 2.1.2
+ requiresBuild: true
+ optional: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==, tarball: https://r2.cnpmjs.org/source-map/-/source-map-0.6.1.tgz}
+ name: source-map
+ version: 0.6.1
+ engines: {node: '>=0.10.0'}
+ requiresBuild: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==, tarball: https://r2.cnpmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz}
+ name: sourcemap-codec
+ version: 1.4.8
+ deprecated: Please use @jridgewell/sourcemap-codec instead
+ dev: true
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==, tarball: https://r2.cnpmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz}
+ name: sprintf-js
+ version: 1.0.3
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==, tarball: https://r2.cnpmjs.org/string-width/-/string-width-4.2.3.tgz}
+ name: string-width
+ version: 4.2.3
+ engines: {node: '>=8'}
+ dependencies:
+ emoji-regex: r2.cnpmjs.org/[email protected]
+ is-fullwidth-code-point: r2.cnpmjs.org/[email protected]
+ strip-ansi: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==, tarball: https://r2.cnpmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz}
+ name: strip-ansi
+ version: 6.0.1
+ engines: {node: '>=8'}
+ dependencies:
+ ansi-regex: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==, tarball: https://r2.cnpmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz}
+ name: strip-json-comments
+ version: 3.1.1
+ engines: {node: '>=8'}
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==, tarball: https://r2.cnpmjs.org/universalify/-/universalify-0.1.2.tgz}
+ name: universalify
+ version: 0.1.2
+ engines: {node: '>= 4.0.0'}
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==, tarball: https://r2.cnpmjs.org/uri-js/-/uri-js-4.4.1.tgz}
+ name: uri-js
+ version: 4.4.1
+ dependencies:
+ punycode: 2.3.1
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==, tarball: https://r2.cnpmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz}
+ name: webidl-conversions
+ version: 3.0.1
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==, tarball: https://r2.cnpmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz}
+ name: wrap-ansi
+ version: 7.0.0
+ engines: {node: '>=10'}
+ dependencies:
+ ansi-styles: r2.cnpmjs.org/[email protected]
+ string-width: r2.cnpmjs.org/[email protected]
+ strip-ansi: r2.cnpmjs.org/[email protected]
+
+ r2.cnpmjs.org/[email protected]:
+ resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==, tarball: https://r2.cnpmjs.org/yallist/-/yallist-4.0.0.tgz}
+ name: yallist
+ version: 4.0.0