Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets): data validation validator issues (#4477)
zhangw29b6f9a1e038
diff --git a/packages/core/src/docs/data-model/rich-text-builder.ts b/packages/core/src/docs/data-model/rich-text-builder.tsindex d03a687182..549dc0776b 100644--- a/packages/core/src/docs/data-model/rich-text-builder.ts+++ b/packages/core/src/docs/data-model/rich-text-builder.ts@@ -24,6 +24,60 @@ import { BuildTextUtils } from './text-x/build-utils';import { TextX } from './text-x/text-x';import { getBodySlice } from './text-x/utils';+function normalizeBody(body: IDocumentBody) {+ if (!body.customRanges) {+ body.customRanges = [];+ }++ if (!body.paragraphs) {+ body.paragraphs = [];+ for (let i = 0; i < body.dataStream.length; i++) {+ if (body.dataStream[i] === '\r') {+ body.paragraphs.push({ startIndex: i });+ }+ }+ }++ if (!body.customBlocks) {+ body.customBlocks = [];+ }++ if (!body.textRuns) {+ body.textRuns = [];+ }++ if (!body.customDecorations) {+ body.customDecorations = [];+ }++ if (!body.sectionBreaks) {+ body.sectionBreaks = [];+ }++ if (!body.tables) {+ body.tables = [];+ }++ return body;+}++function normalizeData(data: IDocumentData) {+ data.body = normalizeBody(data.body ?? { dataStream: '' });++ if (!data.drawingsOrder) {+ data.drawingsOrder = [];+ }++ if (!data.drawings) {+ data.drawings = {};+ }+ if (!data.documentStyle) {+ data.documentStyle = {};+ }++ return data;+}+/*** Represents a read-only font style value object.* This class provides access to font style properties without modification capabilities.@@ -1466,6 +1520,10 @@ export class RichTextValue {* Creates a new RichTextValue instance* @param {IDocumentData} data The initial data for the rich text value* @returns {RichTextValue} A new RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * ```*/public static create(data: IDocumentData): RichTextValue {return new RichTextValue(data);@@ -1475,6 +1533,10 @@ export class RichTextValue {* Creates a new RichTextValue instance* @param {IDocumentBody} data The initial data for the rich text value* @returns {RichTextValue} A new RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.createByBody({ dataStream: 'Hello World\r\n' });+ * ```*/public static createByBody(data: IDocumentBody): RichTextValue {return new RichTextValue({ body: data, id: 'd', documentStyle: {} });@@ -1484,12 +1546,17 @@ export class RichTextValue {if (!data.body) {throw new Error('Invalid document data, body is required');}- this._data = data;+ this._data = normalizeData(data);}/*** Creates a copy of the current RichTextValue instance* @returns {RichTextValue} A new instance of RichTextValue with the same data+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const copy = richText.copy();+ * ```*/copy(): RichTextBuilder {return RichTextBuilder.create(Tools.deepClone(this._data));@@ -1500,6 +1567,11 @@ export class RichTextValue {* @param {number} start The start index* @param {number} end The end index* @returns {RichTextBuilder} A new instance of RichTextBuilder with the sliced data+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const sliced = richText.slice(0, 5);+ * ```*/slice(start: number, end: number): RichTextBuilder {const { body, ...ext } = this._data;@@ -1512,14 +1584,24 @@ export class RichTextValue {/*** Converts the current RichTextValue instance to plain text* @returns {string} The plain text representation of the current RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const plainText = richText.toPlainText();+ * ```*/toPlainText(): string {- return BuildTextUtils.transform.getPlainText(this._data.body?.dataStream ?? '');+ return BuildTextUtils.transform.getPlainText(this._data.body?.dataStream ?? '').replaceAll('\r', '\n');}/*** Gets the paragraph style of the current RichTextValue instance* @returns {ParagraphStyleValue} The paragraph style of the current RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const style = richText.getParagraphStyle();+ * ```*/getParagraphStyle(): ParagraphStyleValue {return ParagraphStyleValue.create(this._data.body?.paragraphs?.[0].paragraphStyle);@@ -1528,6 +1610,11 @@ export class RichTextValue {/*** Gets the paragraph bullet of the current RichTextValue instance* @returns {ParagraphBulletValue} The paragraph bullet of the current RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const bullet = richText.getParagraphBullet();+ * ```*/getParagraphBullet() {return this._data.body?.paragraphs?.[0].bullet;@@ -1536,6 +1623,11 @@ export class RichTextValue {/*** Gets the paragraphs of the current RichTextValue instance* @returns {RichTextValue[]} The paragraphs of the current RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const paragraphs = richText.getParagraphs();+ * ```*/getParagraphs(): RichTextValue[] {const paragraphs = this._data.body?.paragraphs ?? [];@@ -1551,6 +1643,11 @@ export class RichTextValue {/*** Gets the text runs of the current RichTextValue instance* @returns {TextRunValue[]} The text runs of the current RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const textRuns = richText.getTextRuns();+ * ```*/getTextRuns() {return (this._data.body?.textRuns ?? []).map((t) => ({@@ -1561,7 +1658,12 @@ export class RichTextValue {/*** Gets the links of the current RichTextValue instance- * @returns {LinkValue[]} The links of the current RichTextValue instance+ * @returns {ICustomRange[]} The links of the current RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const links = richText.getLinks();+ * ```*/getLinks() {return this._data.body?.customRanges?.filter((r) => r.rangeType === CustomRangeType.HYPERLINK) ?? [];@@ -1570,6 +1672,11 @@ export class RichTextValue {/*** Gets the data of the current RichTextValue instance* @returns {IDocumentData} The data of the current RichTextValue instance+ * @example+ * ```ts+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });+ * const data = richText.getData();+ * ```*/getData(): IDocumentData {return this._data;@@ -1622,7 +1729,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.insertText(0, 'World');* ```*/@@ -1635,7 +1742,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.insertText(5, 'World', { ff: 'Arial', fs: 12 });* ```*/@@ -1691,7 +1798,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextValue | IDocumentData} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.insertRichText(RichTextValue.create({ body: { dataStream: 'World' } }));* ```*/@@ -1703,7 +1810,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextValue | IDocumentData} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.insertRichText(5, RichTextValue.create({ body: { dataStream: 'World' } }));* ```*/@@ -1738,7 +1845,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello World' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.delete(5);* ```*/@@ -1750,7 +1857,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello World' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.delete(5, 5);* ```*/@@ -1773,7 +1880,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello World' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.setStyle(5, 10, { ff: 'Arial', fs: 12 });* ```*/@@ -1799,7 +1906,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello World' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.setLink(5, 10, 'https://www.example.com');* ```*/@@ -1828,7 +1935,7 @@ export class RichTextBuilder extends RichTextValue {* ```ts* const richText = RichTextValue.create({* body: {- * dataStream: 'Hello World',+ * dataStream: 'Hello World\r\n',* customRanges: [* {* rangeType: CustomRangeType.HYPERLINK,@@ -1852,7 +1959,7 @@ export class RichTextBuilder extends RichTextValue {* ```ts* const richText = RichTextValue.create({* body: {- * dataStream: 'Hello World',+ * dataStream: 'Hello World\r\n',* customRanges: [* {* rangeType: CustomRangeType.HYPERLINK,@@ -1911,7 +2018,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello World' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.insertParagraph();* ```*/@@ -1923,7 +2030,7 @@ export class RichTextBuilder extends RichTextValue {* @returns {RichTextBuilder} The current RichTextBuilder instance* @example* ```ts- * const richText = RichTextValue.create({ body: { dataStream: 'Hello World' } });+ * const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });* const newRichText = richText.insertParagraph(5, { ff: 'Arial', fs: 12 });* ```*/diff --git a/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx b/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsxindex 80da58d5a8..2f99dd1f5c 100644--- a/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx+++ b/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx@@ -57,7 +57,10 @@ export const MentionEditPopup = () => {return (<MentionListeditorId={editPopup.unitId}- onClick={() => popupService.closeEditPopup()}+ onClick={() => {+ popupService.closeEditPopup();+ editorService.focus(editPopup.unitId);+ }}mentions={mentions}onSelect={async (mention) => {await commandService.executeCommand(AddDocMentionCommand.id, {diff --git a/packages/docs-ui/src/basics/paragraph.ts b/packages/docs-ui/src/basics/paragraph.tsindex c5a2f6453d..9ce46f599d 100644--- a/packages/docs-ui/src/basics/paragraph.ts+++ b/packages/docs-ui/src/basics/paragraph.ts@@ -69,10 +69,12 @@ export function getTextRunAtPosition(export function getCustomRangeAtPosition(customRanges: ICustomRange[], position: number, extendRange?: boolean) {if (extendRange) {- return customRanges.find((customRange) => position >= customRange.startIndex && position <= customRange.endIndex + 1);+ const range = customRanges.find((customRange) => position >= customRange.startIndex && position <= customRange.endIndex + 1);+ return range?.wholeEntity ? null : range;}- return customRanges.find((customRange) => position > customRange.startIndex && position <= customRange.endIndex);+ const range = customRanges.find((customRange) => position > customRange.startIndex && position <= customRange.endIndex);+ return range?.wholeEntity ? null : range;}export function getCustomDecorationAtPosition(customDecorations: ICustomDecoration[], position: number) {diff --git a/packages/docs-ui/src/controllers/menu/context-menu.ts b/packages/docs-ui/src/controllers/menu/context-menu.tsindex ceb0d15e7b..58658acc69 100644--- a/packages/docs-ui/src/controllers/menu/context-menu.ts+++ b/packages/docs-ui/src/controllers/menu/context-menu.ts@@ -18,7 +18,7 @@ import type { IAccessor } from '@univerjs/core';import type { IRectRangeWithStyle } from '@univerjs/engine-render';import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';import type { Subscriber } from 'rxjs';-import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';+import { DOC_RANGE_TYPE, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { DocSelectionManagerService } from '@univerjs/docs';import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';import { combineLatest, Observable } from 'rxjs';@@ -32,8 +32,9 @@ const getDisableOnCollapsedObservable = (accessor: IAccessor) => {const docSelectionManagerService = accessor.get(DocSelectionManagerService);return new Observable<boolean>((subscriber) => {const observable = docSelectionManagerService.textSelection$.subscribe(() => {- const range = docSelectionManagerService.getActiveTextRange();- if (range && !range.collapsed) {+ const ranges = docSelectionManagerService.getDocRanges();+ const legal = ranges.some((range) => range.collapsed === false || range.rangeType === DOC_RANGE_TYPE.RECT);+ if (legal) {subscriber.next(false);} else {subscriber.next(true);diff --git a/packages/docs-ui/src/views/rich-text-editor/index.tsx b/packages/docs-ui/src/views/rich-text-editor/index.tsxindex 30ea8da0a6..d1702c12f7 100644--- a/packages/docs-ui/src/views/rich-text-editor/index.tsx+++ b/packages/docs-ui/src/views/rich-text-editor/index.tsx@@ -90,7 +90,7 @@ export const RichTextEditor = forwardRef<Editor, IRichTextEditorProps>((props, rconst size = docSkeleton?.getSkeleton().getActualSize();if (size) {onHeightChange?.(size.actualHeight);- setHeight(Math.max(defaultHeight, Math.min(size.actualHeight, maxHeight)));+ setHeight(Math.max(defaultHeight, Math.min(size.actualHeight + 10, maxHeight)));}_onChange?.(data);checkScrollBar();diff --git a/packages/sheets-data-validation/src/facade/f-range.ts b/packages/sheets-data-validation/src/facade/f-range.tsindex f05927f354..26dd3a321e 100644--- a/packages/sheets-data-validation/src/facade/f-range.ts+++ b/packages/sheets-data-validation/src/facade/f-range.ts@@ -38,7 +38,7 @@ export interface IFRangeDataValidationMixin {* @returns all data validation rules*/getDataValidations(this: FRange): FDataValidation[];- getValidatorStatus(): Promise<Promise<DataValidationStatus>[][]>;+ getValidatorStatus(): Promise<DataValidationStatus[][]>;}export class FRangeDataValidationMixin extends FRange implements IFRangeDataValidationMixin {@@ -90,7 +90,7 @@ export class FRangeDataValidationMixin extends FRange implements IFRangeDataVali).map((rule) => new FDataValidation(rule, this._worksheet, this._injector));}- override async getValidatorStatus(): Promise<Promise<DataValidationStatus>[][]> {+ override async getValidatorStatus(): Promise<DataValidationStatus[][]> {const validatorService = this._injector.get(SheetsDataValidationValidatorService);return validatorService.validatorRanges(this._workbook.getUnitId(),diff --git a/packages/sheets-data-validation/src/services/dv-validator-service.ts b/packages/sheets-data-validation/src/services/dv-validator-service.tsindex 43fbe55a91..65ce374c97 100644--- a/packages/sheets-data-validation/src/services/dv-validator-service.ts+++ b/packages/sheets-data-validation/src/services/dv-validator-service.ts@@ -127,7 +127,7 @@ export class SheetsDataValidationValidatorService extends Disposable {Range.foreach(range, (row, col) => {promises.push(this._validatorByCell(workbook, worksheet, row, col));});- return promises;+ return Promise.all(promises);}));}diff --git a/packages/sheets-data-validation/src/validators/custom-validator.ts b/packages/sheets-data-validation/src/validators/custom-validator.tsindex a76378cedf..b81e158325 100644--- a/packages/sheets-data-validation/src/validators/custom-validator.ts+++ b/packages/sheets-data-validation/src/validators/custom-validator.ts@@ -18,6 +18,7 @@ import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidimport type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';import { CellValueType, DataValidationType, isFormulaString, Tools } from '@univerjs/core';import { BaseDataValidator } from '@univerjs/data-validation';+import { LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula';import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';import { isLegalFormulaResult } from '../utils/formula';@@ -28,12 +29,17 @@ export class CustomFormulaValidator extends BaseDataValidator {override scopes: string | string[] = ['sheet'];private readonly _customFormulaService = this.injector.get(DataValidationCustomFormulaService);+ private readonly _lexerTreeBuilder = this.injector.get(LexerTreeBuilder);override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {const success = isFormulaString(rule.formula1);+ const formulaText = rule.formula1 ?? '';+ const result = this._lexerTreeBuilder.checkIfAddBracket(formulaText);+ const valid = result === 0 && formulaText.startsWith(operatorToken.EQUALS);+return {- success,- formula1: success ? '' : this.localeService.t('dataValidation.validFail.formula'),+ success: success && valid,+ formula1: success && valid ? '' : this.localeService.t('dataValidation.validFail.formula'),};}diff --git a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx b/packages/sheets-formula-ui/src/views/formula-editor/index.tsxindex 95026a69df..b84d5888da 100644--- a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx+++ b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx@@ -72,6 +72,7 @@ export interface IFormulaEditorProps {* Disable selection when click formula editor*/disableSelectionOnClick?: boolean;+ disableContextMenu?: boolean;}const noop = () => { };@@ -98,6 +99,7 @@ export function FormulaEditor(props: IFormulaEditorProps) {autoScrollbar = true,isSingle = true,disableSelectionOnClick = false,+ disableContextMenu,} = props;const editorService = useDependency(IEditorService);@@ -236,7 +238,7 @@ export function FormulaEditor(props: IFormulaEditorProps) {}, [_isFocus, editor, focus, resetSelection, resetSelectionOnBlur]);const { checkScrollBar } = useResize(editor, isSingle, autoScrollbar);- useRefactorEffect(isFocus, Boolean(isSelecting && docFocusing), unitId);+ useRefactorEffect(isFocus, Boolean(isSelecting && docFocusing), unitId, disableContextMenu);useLeftAndRightArrow(isFocus && moveCursor, selectingMode, editor, onMoveInEditor);const handleSelectionChange = useEvent((refString: string, offset: number, isEnd: boolean) => {diff --git a/packages/sheets-formula-ui/src/views/range-selector/hooks/useRefactorEffect.ts b/packages/sheets-formula-ui/src/views/range-selector/hooks/useRefactorEffect.tsindex f8fc9c53b4..36d199af5a 100644--- a/packages/sheets-formula-ui/src/views/range-selector/hooks/useRefactorEffect.ts+++ b/packages/sheets-formula-ui/src/views/range-selector/hooks/useRefactorEffect.ts@@ -22,7 +22,7 @@ import { IContextMenuService } from '@univerjs/ui';import { useEffect, useLayoutEffect } from 'react';import { RefSelectionsRenderService } from '../../../services/render-services/ref-selections.render-service';-export const useRefactorEffect = (isNeed: boolean, selecting: boolean, unitId: string) => {+export const useRefactorEffect = (isNeed: boolean, selecting: boolean, unitId: string, disableContextMenu = true) => {const renderManagerService = useDependency(IRenderManagerService);const contextService = useDependency(IContextService);const contextMenuService = useDependency(IContextMenuService);@@ -58,13 +58,13 @@ export const useRefactorEffect = (isNeed: boolean, selecting: boolean, unitId: suseEffect(() => {if (isNeed) {contextService.setContextValue(EDITOR_ACTIVATED, true);- contextMenuService.disable();+ disableContextMenu && contextMenuService.disable();return () => {contextService.setContextValue(EDITOR_ACTIVATED, false);- contextMenuService.enable();+ disableContextMenu && contextMenuService.enable();};}- }, [contextMenuService, contextService, isNeed]);+ }, [contextMenuService, contextService, isNeed, disableContextMenu]);// reset setSkipLastEnableduseEffect(() => {diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.tsindex 9d0b26b718..a2ad9d4c93 100644--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts@@ -567,6 +567,9 @@ export class EditingRenderController extends Disposable implements IRenderModule}const finalCell = await this._sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, cellData);+ if (finalCell === worksheet.getCellRaw(row, column)) {+ return;+ }this._commandService.executeCommand(SetRangeValuesCommand.id, {subUnitId: sheetId,unitId,diff --git a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsxindex 5fd96fc51c..1e1fa8476c 100644--- a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx+++ b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx@@ -172,6 +172,7 @@ export const EditorContainer: React.FC<ICellIEditorProps> = () => {}}}disableSelectionOnClick+ disableContextMenu={false}/>)}</div>diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsxindex 9a27c81a8d..4a4fdce2b8 100644--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx@@ -249,6 +249,7 @@ export function FormulaBar() {}}}autoScrollbar={false}+ disableContextMenu={false}/>)}</div>diff --git a/packages/sheets/src/facade/f-range.ts b/packages/sheets/src/facade/f-range.tsindex 88ccff11db..5ee057dcb3 100644--- a/packages/sheets/src/facade/f-range.ts+++ b/packages/sheets/src/facade/f-range.ts@@ -41,7 +41,14 @@ export class FRange extends FBaseInitialable {/*** Get the unit ID of the current workbook- * @returns The unit ID of the workbook+ * @returns {string} The unit ID of the workbook+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getUnitId()+ * ```*/getUnitId(): string {return this._workbook.getUnitId();@@ -49,7 +56,14 @@ export class FRange extends FBaseInitialable {/*** Gets the name of the worksheet- * @returns The name of the worksheet+ * @returns {string} The name of the worksheet+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getSheetName()+ * ```*/getSheetName(): string {return this._worksheet.getName();@@ -57,7 +71,14 @@ export class FRange extends FBaseInitialable {/*** Gets the ID of the worksheet- * @returns The ID of the worksheet+ * @returns {string} The ID of the worksheet+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getSheetId()+ * ```*/getSheetId(): string {return this._worksheet.getSheetId();@@ -65,7 +86,14 @@ export class FRange extends FBaseInitialable {/*** Gets the area where the statement is applied- * @returns The area where the statement is applied+ * @returns {IRange} The area where the statement is applied+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getRange()+ * ```*/getRange(): IRange {return this._range;@@ -73,7 +101,14 @@ export class FRange extends FBaseInitialable {/*** Gets the starting row number of the applied area- * @returns The starting row number of the area+ * @returns {number} The starting row number of the area+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getRow()+ * ```*/getRow(): number {return this._range.startRow;@@ -81,7 +116,14 @@ export class FRange extends FBaseInitialable {/*** Gets the starting column number of the applied area- * @returns The starting column number of the area+ * @returns {number} The starting column number of the area+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getColumn()+ * ```*/getColumn(): number {return this._range.startColumn;@@ -89,7 +131,14 @@ export class FRange extends FBaseInitialable {/*** Gets the width of the applied area- * @returns The width of the area+ * @returns {number} The width of the area+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getWidth()+ * ```*/getWidth(): number {return this._range.endColumn - this._range.startColumn + 1;@@ -97,7 +146,14 @@ export class FRange extends FBaseInitialable {/*** Gets the height of the applied area- * @returns The height of the area+ * @returns {number} The height of the area+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getHeight()+ * ```*/getHeight(): number {return this._range.endRow - this._range.startRow + 1;@@ -105,7 +161,14 @@ export class FRange extends FBaseInitialable {/*** Return range whether this range is merged- * @returns if true is merged+ * @returns {boolean} if true is merged+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .isMerged()+ * ```*/isMerged(): boolean {const { startColumn, startRow, endColumn, endRow } = this._range;@@ -116,6 +179,13 @@ export class FRange extends FBaseInitialable {/*** Return first cell style data in this range* @returns {IStyleData | null} The cell style data+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getCellStyleData()+ * ```*/getCellStyleData(): IStyleData | null {const cell = this.getCellData();@@ -128,17 +198,14 @@ export class FRange extends FBaseInitialable {}/**- * Returns the value of the cell at the start of this range.- * @returns {CellValue | null} The value of the cell.+ * @deprecated use `getValueAndRichTextValue` instead. This api can't return rich text value.*/getValue(): CellValue | null {return this._worksheet.getCell(this._range.startRow, this._range.startColumn)?.v ?? null;}/**- * Returns the rectangular grid of values for this range.- * Returns a two-dimensional array of values, indexed by row, then by column.- * @returns {Nullable<CellValue>[][]} A two-dimensional array of values.+ * @deprecated use `getValueAndRichTextValues` instead. This api can't return rich text value.*/getValues(): Nullable<CellValue>[][] {const { startRow, endRow, startColumn, endColumn } = this._range;@@ -160,7 +227,7 @@ export class FRange extends FBaseInitialable {* Return first cell model data in this range* @returns {ICellData | null} The cell model data* @example- * ```+ * ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()* .getActiveRange()@@ -175,7 +242,7 @@ export class FRange extends FBaseInitialable {* Returns the cell data for the cells in the range.* @returns {Nullable<ICellData>[][]} A two-dimensional array of cell data.* @example- * ```+ * ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()* .getActiveRange()@@ -207,7 +274,7 @@ export class FRange extends FBaseInitialable {* Returns the rich text value for the cell at the start of this range.* @returns {Nullable<RichTextValue>} The rich text value* @example- * ```+ * ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()* .getActiveRange()@@ -226,7 +293,7 @@ export class FRange extends FBaseInitialable {* Returns the rich text value for the cells in the range.* @returns {Nullable<RichTextValue>[][]} A two-dimensional array of RichTextValue objects.* @example- * ```+ * ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()* .getActiveRange()@@ -242,7 +309,7 @@ export class FRange extends FBaseInitialable {* Returns the value and rich text value for the cell at the start of this range.* @returns {Nullable<CellValue | RichTextValue>} The value and rich text value* @example- * ```+ * ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()* .getActiveRange()@@ -258,7 +325,7 @@ export class FRange extends FBaseInitialable {* Returns the value and rich text value for the cells in the range.* @returns {Nullable<CellValue | RichTextValue>[][]} A two-dimensional array of value and rich text value* @example- * ```+ * ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()* .getActiveRange()@@ -302,18 +369,62 @@ export class FRange extends FBaseInitialable {return formulas;}+ /**+ * Returns true if the cell wrap is enabled+ * @returns {boolean} True if the cell wrap is enabled+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getWrap()+ * ```+ */getWrap(): boolean {return this._worksheet.getRange(this._range).getWrap() === BooleanNumber.TRUE;}+ /**+ * Returns the text wrapping strategy for the top left cell of the range.+ * @returns {WrapStrategy} The text wrapping strategy+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getWrapStrategy()+ * ```+ */getWrapStrategy(): WrapStrategy {return this._worksheet.getRange(this._range).getWrapStrategy();}+ /**+ * Returns the horizontal alignment for the top left cell of the range.+ * @returns {string} The horizontal alignment+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getHorizontalAlignment()+ * ```+ */getHorizontalAlignment(): string {return transformCoreHorizontalAlignment(this._worksheet.getRange(this._range).getHorizontalAlignment());}+ /**+ * Returns the vertical alignment for the top left cell of the range.+ * @returns {string} The vertical alignment+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getVerticalAlignment()+ * ```+ */getVerticalAlignment(): string {return transformCoreVerticalAlignment(this._worksheet.getRange(this._range).getVerticalAlignment());}@@ -386,9 +497,10 @@ export class FRange extends FBaseInitialable {/*** Set background color for current range.- * @param color {string}+ * @param {string} color The background color+ * @returns {FRange} This range, for chaining* @example- * ```+ * ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()* .getActiveRange()@@ -412,11 +524,12 @@ export class FRange extends FBaseInitialable {/*** Set background color for current range.+ * @param {string} color The background color+ * @returns {FRange} This range, for chaining* @example* ```typescript* univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')* ```- * @param color {string}*/setBackground(color: string): FRange {this.setBackgroundColor(color);@@ -426,6 +539,13 @@ export class FRange extends FBaseInitialable {/*** Set new value for current cell, first cell in this range.* @param {CellValue | ICellData} value The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.+ * @returns {FRange} This range, for chaining+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setValue(1);+ * ```*/setValue(value: CellValue | ICellData): FRange {const realValue = covertCellValue(value);@@ -447,6 +567,7 @@ export class FRange extends FBaseInitialable {/*** Set new value for current cell, first cell in this range.* @param {CellValue | ICellData} value The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.+ * @returns {FRange} This range, for chaining* ```ts* univerAPI.getActiveWorkbook()* .getActiveSheet()@@ -535,7 +656,15 @@ export class FRange extends FBaseInitialable {/*** Set the cell wrap of the given range.* Cells with wrap enabled (the default) resize to display their full content. Cells with wrap disabled display as much as possible in the cell without resizing or running to multiple lines.- * @param isWrapEnabled+ * @param {boolean} isWrapEnabled Whether to enable wrap+ * @returns {FRange} this range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setWrap(true);+ * ```*/setWrap(isWrapEnabled: boolean): FRange {this._commandService.syncExecuteCommand(SetTextWrapCommand.id, {@@ -550,7 +679,15 @@ export class FRange extends FBaseInitialable {/*** Sets the text wrapping strategy for the cells in the range.- * @param strategy+ * @param {WrapStrategy} strategy The text wrapping strategy+ * @returns {FRange} this range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setWrapStrategy(WrapStrategy.WRAP);+ * ```*/setWrapStrategy(strategy: WrapStrategy): FRange {this._commandService.syncExecuteCommand(SetTextWrapCommand.id, {@@ -565,7 +702,15 @@ export class FRange extends FBaseInitialable {/*** Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).- * @param alignment+ * @param {"top" | "middle" | "bottom"} alignment The vertical alignment+ * @returns {FRange} this range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setVerticalAlignment('top');+ * ```*/setVerticalAlignment(alignment: FVerticalAlignment): FRange {this._commandService.syncExecuteCommand(SetVerticalTextAlignCommand.id, {@@ -580,7 +725,15 @@ export class FRange extends FBaseInitialable {/*** Set the horizontal (left to right) alignment for the given range (left/center/right).- * @param alignment+ * @param {"left" | "center" | "normal"} alignment The horizontal alignment+ * @returns {FRange} this range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setHorizontalAlignment('left');+ * ```*/setHorizontalAlignment(alignment: FHorizontalAlignment): FRange {this._commandService.syncExecuteCommand(SetHorizontalTextAlignCommand.id, {@@ -595,7 +748,15 @@ export class FRange extends FBaseInitialable {/*** Sets a different value for each cell in the range. The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats. If a value begins with `=`, it is interpreted as a formula.- * @param value+ * @param {CellValue[][] | IObjectMatrixPrimitiveType<CellValue> | ICellData[][] | IObjectMatrixPrimitiveType<ICellData>} value The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats.+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setValues([[1, 2], [3, 4]]);+ * ```*/setValues(value:@@ -618,7 +779,15 @@ export class FRange extends FBaseInitialable {/*** Sets the font weight for the given range (normal/bold),- * @param fontWeight The font weight, either 'normal' or 'bold'; a null value resets the font weight.+ * @param {FontWeight|null} fontWeight The font weight, either 'normal' or 'bold'; a null value resets the font weight.+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setFontWeight('bold');+ * ```*/setFontWeight(fontWeight: FontWeight | null): this {let value: BooleanNumber | null;@@ -651,7 +820,15 @@ export class FRange extends FBaseInitialable {/*** Sets the font style for the given range ('italic' or 'normal').- * @param fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.+ * @param {FontStyle|null} fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setFontStyle('italic');+ * ```*/setFontStyle(fontStyle: FontStyle | null): this {let value: BooleanNumber | null;@@ -684,7 +861,15 @@ export class FRange extends FBaseInitialable {/*** Sets the font line style of the given range ('underline', 'line-through', or 'none').- * @param fontLine The font line style, either 'underline', 'line-through', or 'none'; a null value resets the font line style.+ * @param {FontLine|null} fontLine The font line style, either 'underline', 'line-through', or 'none'; a null value resets the font line style.+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setFontLine('underline');+ * ```*/setFontLine(fontLine: FontLine | null): this {if (fontLine === 'underline') {@@ -713,7 +898,15 @@ export class FRange extends FBaseInitialable {/*** Sets the font underline style of the given ITextDecoration- * @param value+ * @param {ITextDecoration|null} value The font underline style of the given ITextDecoration; a null value resets the font underline style+ * @returns {void}+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setFontLine('underline');+ * ```*/private _setFontUnderline(value: ITextDecoration | null): void {const style: IStyleTypeValue<ITextDecoration | null> = {@@ -732,7 +925,8 @@ export class FRange extends FBaseInitialable {/*** Sets the font strikethrough style of the given ITextDecoration- * @param value+ * @param {ITextDecoration|null} value The font strikethrough style of the given ITextDecoration; a null value resets the font strikethrough style+ * @returns {void}*/private _setFontStrikethrough(value: ITextDecoration | null): void {const style: IStyleTypeValue<ITextDecoration | null> = {@@ -751,7 +945,15 @@ export class FRange extends FBaseInitialable {/*** Sets the font family, such as "Arial" or "Helvetica".- * @param fontFamily The font family to set; a null value resets the font family.+ * @param {string|null} fontFamily The font family to set; a null value resets the font family.+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setFontFamily('Arial');+ * ```*/setFontFamily(fontFamily: string | null): this {const style: IStyleTypeValue<string | null> = {@@ -772,7 +974,15 @@ export class FRange extends FBaseInitialable {/*** Sets the font size, with the size being the point size to use.- * @param size A font size in point size. A null value resets the font size.+ * @param {number|null} size A font size in point size. A null value resets the font size.+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setFontSize(12);+ * ```*/setFontSize(size: number | null): this {const style: IStyleTypeValue<number | null> = {@@ -793,7 +1003,15 @@ export class FRange extends FBaseInitialable {/*** Sets the font color in CSS notation (such as '#ffffff' or 'white').- * @param color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.+ * @param {string|null} color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setFontColor('#ff0000');+ * ```*/setFontColor(color: string | null): this {const value: IColorStyle | null = color === null ? null : { rgb: color };@@ -820,8 +1038,8 @@ export class FRange extends FBaseInitialable {/*** Merge cells in a range into one merged cell- * @param [defaultMerge] - If true, only the value in the upper left cell is retained.- * @returns This range, for chaining+ * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.+ * @returns {FRange} This range, for chaining* @example* ```ts* const workbook = univerAPI.getActiveWorkbook();@@ -843,8 +1061,8 @@ export class FRange extends FBaseInitialable {/*** Merges cells in a range horizontally.- * @param [defaultMerge] - If true, only the value in the upper left cell is retained.- * @returns This range, for chaining+ * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.+ * @returns {FRange} This range, for chaining* @example* ```ts* const workbook = univerAPI.getActiveWorkbook();@@ -867,8 +1085,8 @@ export class FRange extends FBaseInitialable {/*** Merges cells in a range vertically.- * @param [defaultMerge] - If true, only the value in the upper left cell is retained.- * @returns This range, for chaining+ * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.+ * @returns {FRange} This range, for chaining* @example* ```ts* const workbook = univerAPI.getActiveWorkbook();@@ -910,7 +1128,7 @@ export class FRange extends FBaseInitialable {/*** Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.- * @returns This range, for chaining+ * @returns {FRange} This range, for chaining* @example* ```ts* const workbook = univerAPI.getActiveWorkbook();@@ -934,7 +1152,7 @@ export class FRange extends FBaseInitialable {/*** Iterate cells in this range. Merged cells will be respected.- * @param callback the callback function to be called for each cell in the range+ * @param {Function} callback the callback function to be called for each cell in the range* @param {number} callback.row the row number of the cell* @param {number} callback.col the column number of the cell* @param {ICellData} callback.cell the cell data@@ -959,7 +1177,7 @@ export class FRange extends FBaseInitialable {/*** Returns a string description of the range, in A1 notation.- * @param withSheet+ * @param {boolean} [withSheet] - If true, the sheet name is included in the A1 notation.* @returns {string} The A1 notation of the range.* ```ts* const fWorkbook = univerAPI.getActiveWorkbook();