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
feat(sheet): support range theme template (#4369)
VicKun28ff41a3a2db
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERSindex c34c6af765..61998fab12 100644--- a/.github/CODEOWNERS+++ b/.github/CODEOWNERS@@ -89,3 +89,7 @@ packages/slides-ui @jikkai## Facade API**/facade/** @weird94 @VicKun4937++## Collaboration++**/mutations/** @yuhongz @wzhudevdiff --git a/packages/core/src/sheets/typedef.ts b/packages/core/src/sheets/typedef.tsindex 1526f3316a..3bb17ba4e2 100644--- a/packages/core/src/sheets/typedef.ts+++ b/packages/core/src/sheets/typedef.ts@@ -272,6 +272,14 @@ export interface ICellMarks {isSkip?: boolean;}+export interface IFontRenderExtension {+ leftOffset?: number;+ rightOffset?: number;+ topOffset?: number;+ downOffset?: number;+ isSkip?: boolean;+}+// TODO@weird94: should be moved outside of the core packageexport interface ICellDataForSheetInterceptor extends ICellData {interceptorStyle?: Nullable<IStyleData>;@@ -286,13 +294,10 @@ export interface ICellDataForSheetInterceptor extends ICellData {coverable?: boolean;linkUrl?: string;linkId?: string;- fontRenderExtension?: {- leftOffset?: number;- rightOffset?: number;- topOffset?: number;- downOffset?: number;- isSkip?: boolean;- };+ fontRenderExtension?: IFontRenderExtension;+ // use for save the theme style, it can not be composed directly+ themeStyle?: Nullable<IStyleData>;+}export function isICellData(value: any): value is ICellData {diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.tsindex 22f9eeb28a..993f41c6fa 100644--- a/packages/engine-render/src/components/sheets/extensions/font.ts+++ b/packages/engine-render/src/components/sheets/extensions/font.ts@@ -17,7 +17,7 @@/* eslint-disable max-lines-per-function *//* eslint-disable complexity */-import type { ICellDataForSheetInterceptor, ICellWithCoord, IDocDrawingBase, ImageSourceType, IRange, IScale, Nullable, ObjectMatrix } from '@univerjs/core';+import type { ICellWithCoord, IDocDrawingBase, ImageSourceType, IRange, IScale, Nullable, ObjectMatrix } from '@univerjs/core';import type { UniverRenderingContext } from '../../../context';import type { Documents } from '../../docs/document';import type { IDrawInfo } from '../../extension';@@ -53,7 +53,9 @@ interface IRenderFontContext {diffRanges: IRange[];spreadsheetSkeleton: SpreadsheetSkeleton;overflowRectangle: Nullable<IRange>;- cellData: Nullable<ICellDataForSheetInterceptor>;+ cellData: Nullable<{+ fontCache: Nullable<IFontCacheItem>;+ }>;startY: number;endY: number;startX: number;@@ -134,7 +136,6 @@ export class Font extends SheetExtension {Range.foreach(range, (row, col) => {const index = spreadsheetSkeleton.worksheet.getSpanModel().getMergeDataIndex(row, col);- // put all merged cells to another pass to render. -1 means not merged.if (index !== -1) {return;}@@ -181,8 +182,8 @@ export class Font extends SheetExtension {//#endregion- const fontsConfig = fontMatrix.getValue(row, col);- if (!fontsConfig) return true;+ const fontCache = fontMatrix.getValue(row, col);+ if (!fontCache) return true;//#region overflow// If the cell is overflowing, but the overflowRectangle has not been set,@@ -204,8 +205,8 @@ export class Font extends SheetExtension {const visibleCol = spreadsheetSkeleton.worksheet.getColVisible(col);if (!visibleRow || !visibleCol) return true;- const cellData = spreadsheetSkeleton.worksheet.getCell(row, col) as ICellDataForSheetInterceptor || {};- if (cellData.fontRenderExtension?.isSkip) {+ //spreadsheetSkeleton.worksheet.getCell(row, col)+ if (fontCache.fontRenderExtension?.isSkip) {return true;}@@ -214,21 +215,21 @@ export class Font extends SheetExtension {//#region text overflowrenderFontCtx.overflowRectangle = overflowRange;- renderFontCtx.cellData = cellData;- this._setFontRenderBounds(renderFontCtx, row, col, fontMatrix);+ renderFontCtx.cellData = { fontCache };+ this._setFontRenderBounds(renderFontCtx, row, col, fontCache);//#endregionctx.translate(renderFontCtx.startX + FIX_ONE_PIXEL_BLUR_OFFSET, renderFontCtx.startY + FIX_ONE_PIXEL_BLUR_OFFSET);- this._renderDocuments(ctx, fontsConfig, renderFontCtx.startX, renderFontCtx.startY, renderFontCtx.endX, renderFontCtx.endY, row, col, spreadsheetSkeleton.overflowCache);+ this._renderDocuments(ctx, fontCache, renderFontCtx.startX, renderFontCtx.startY, renderFontCtx.endX, renderFontCtx.endY, row, col, spreadsheetSkeleton.overflowCache);ctx.closePath();ctx.restore();- const documentDataModel = fontsConfig.documentSkeleton.getViewModel().getDataModel();+ const documentDataModel = fontCache.documentSkeleton.getViewModel().getDataModel();if (documentDataModel.getDrawingsOrder()?.length) {ctx.save();ctx.beginPath();- this._setFontRenderBounds(renderFontCtx, row, col, fontMatrix, 1);- this._renderImages(ctx, fontsConfig, renderFontCtx.startX, renderFontCtx.startY, renderFontCtx.endX, renderFontCtx.endY);+ this._setFontRenderBounds(renderFontCtx, row, col, fontCache, 1);+ this._renderImages(ctx, fontCache, renderFontCtx.startX, renderFontCtx.startY, renderFontCtx.endX, renderFontCtx.endY);ctx.closePath();ctx.restore();}@@ -318,15 +319,14 @@ export class Font extends SheetExtension {* @param renderFontContext* @param row* @param col- * @param fontMatrix+ * @param fontCache*/- private _setFontRenderBounds(renderFontContext: IRenderFontContext, row: number, col: number, fontMatrix: ObjectMatrix<IFontCacheItem>, padding = 0) {+ private _setFontRenderBounds(renderFontContext: IRenderFontContext, row: number, col: number, fontsConfig: IFontCacheItem, padding = 0) {const { ctx, scale, overflowRectangle, rowHeightAccumulation, columnWidthAccumulation, cellData } = renderFontContext;let { startX, endX, startY, endY } = renderFontContext;// https://github.com/dream-num/univer-pro/issues/334// When horizontal alignment is not set, the default alignment for rotation angles varies to accommodate overflow scenarios.- const fontsConfig = fontMatrix.getValue(row, col)!;const { horizontalAlign, vertexAngle = 0, centerAngle = 0 } = fontsConfig;let horizontalAlignOverFlow = horizontalAlign;if (horizontalAlign === HorizontalAlign.UNSPECIFIED) {@@ -337,8 +337,8 @@ export class Font extends SheetExtension {}}- const rightOffset = cellData?.fontRenderExtension?.rightOffset ?? 0;- const leftOffset = cellData?.fontRenderExtension?.leftOffset ?? 0;+ const rightOffset = cellData?.fontCache?.fontRenderExtension?.rightOffset ?? 0;+ const leftOffset = cellData?.fontCache?.fontRenderExtension?.leftOffset ?? 0;let isOverflow = true;if (vertexAngle === 0) {diff --git a/packages/engine-render/src/components/sheets/interfaces.ts b/packages/engine-render/src/components/sheets/interfaces.tsindex c8e1fe1601..5d8784c946 100644--- a/packages/engine-render/src/components/sheets/interfaces.ts+++ b/packages/engine-render/src/components/sheets/interfaces.ts@@ -18,6 +18,7 @@ import type {BorderStyleTypes,HorizontalAlign,ICellWithCoord,+ IFontRenderExtension,ImageCacheMap,ObjectMatrix,VerticalAlign,@@ -52,6 +53,7 @@ export interface IFontCacheItem {wrapStrategy: WrapStrategy;// content?: string;imageCacheMap: ImageCacheMap;+ fontRenderExtension?: IFontRenderExtension;}type colorString = string;diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.tsindex 09be9c563c..136d42691a 100644--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts@@ -2036,6 +2036,7 @@ export class SpreadsheetSkeleton extends Skeleton {horizontalAlign,wrapStrategy,imageCacheMap: this._imageCacheMap,+ fontRenderExtension: cell?.fontRenderExtension,};this._stylesCache.fontMatrix.setValue(row, col, config);this._calculateOverflowCell(row, col, config);@@ -2088,11 +2089,14 @@ export class SpreadsheetSkeleton extends Skeleton {const rowStyle = this.worksheet.getRowStyle(row) as IStyleData;const defaultStyle = this.worksheet.getDefaultCellStyleInternal();- const style = this._isRowStylePrecedeColumnStyle ? composeStyles(defaultStyle, columnStyle, rowStyle, cellStyle) : composeStyles(defaultStyle, rowStyle, columnStyle, cellStyle);+ const style = this._isRowStylePrecedeColumnStyle+ ? composeStyles(defaultStyle, columnStyle, rowStyle, (cell as ICellDataForSheetInterceptor)?.themeStyle, cellStyle)+ : composeStyles(defaultStyle, rowStyle, columnStyle, (cell as ICellDataForSheetInterceptor)?.themeStyle, cellStyle);this._setBgStylesCache(row, col, style, options);this._setBorderStylesCache(row, col, style, options);- this._setFontStylesCache(row, col, cell);++ this._setFontStylesCache(row, col, { ...cell, ...{ s: style } });}private _updateConfigAndGetDocumentModel(diff --git a/packages/sheets/src/basics/const/command-listener-const.ts b/packages/sheets/src/basics/const/command-listener-const.tsindex a3148b7b2b..b0acb6a2dc 100644--- a/packages/sheets/src/basics/const/command-listener-const.ts+++ b/packages/sheets/src/basics/const/command-listener-const.ts@@ -15,6 +15,8 @@*/import { AddWorksheetMergeMutation } from '../../commands/mutations/add-worksheet-merge.mutation';+import { SetWorksheetRangeThemeStyleMutation } from '../../commands/mutations/add-worksheet-range-theme.mutation';+import { DeleteWorksheetRangeThemeStyleMutation } from '../../commands/mutations/delete-worksheet-range-theme.mutation';import { InsertColMutation, InsertRowMutation } from '../../commands/mutations/insert-row-col.mutation';import { MoveRangeMutation } from '../../commands/mutations/move-range.mutation';import { MoveColsMutation, MoveRowsMutation } from '../../commands/mutations/move-rows-cols.mutation';@@ -69,4 +71,6 @@ export const COMMAND_LISTENER_VALUE_CHANGE = [SetWorksheetDefaultStyleMutation.id,SetRowDataMutation.id,SetColDataMutation.id,+ SetWorksheetRangeThemeStyleMutation.id,+ DeleteWorksheetRangeThemeStyleMutation.id,];diff --git a/packages/sheets/src/basics/interfaces/mutation-interface.ts b/packages/sheets/src/basics/interfaces/mutation-interface.tsindex 956f971d63..c848801c18 100644--- a/packages/sheets/src/basics/interfaces/mutation-interface.ts+++ b/packages/sheets/src/basics/interfaces/mutation-interface.ts@@ -100,3 +100,10 @@ export interface IAddWorksheetMergeMutationParams {subUnitId: string;ranges: IRange[];}+/** Params of AddWorksheetMergeMutation */+export interface IWorksheetRangeThemeStyleMutationParams {+ unitId: string;+ subUnitId: string;+ range: IRange;+ themeName: string;+}diff --git a/packages/sheets/src/commands/commands/__tests__/range-template-command.sepc.ts b/packages/sheets/src/commands/commands/__tests__/range-template-command.sepc.tsnew file mode 100644index 0000000000..534525281c--- /dev/null+++ b/packages/sheets/src/commands/commands/__tests__/range-template-command.sepc.ts@@ -0,0 +1,136 @@+/**+ * 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 { IColorStyle, Injector, Univer, Workbook } from '@univerjs/core';+import type { RangeThemeStyle } from '../../../model/range-theme-util';+import type { ISetStyleCommandParams } from '../set-style.command';++import { ICommandService, IUniverInstanceService, UndoCommand, UniverInstanceType } from '@univerjs/core';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';+import { SheetRangeThemeModel } from '../../../model/range-theme-model';+import { SetWorksheetRangeThemeStyleMutation } from '../../mutations/add-worksheet-range-theme.mutation';+import { DeleteWorksheetRangeThemeStyleMutation } from '../../mutations/delete-worksheet-range-theme.mutation';+import { SetWorksheetRangeThemeStyleCommand } from '../add-worksheet-range-theme.command';+import { DeleteWorksheetRangeThemeStyleCommand } from '../delete-worksheet-range-theme.command';+import { SetStyleCommand } from '../set-style.command';+import { createCommandTestBed } from './create-command-test-bed';++// eslint-disable-next-line max-lines-per-function+describe('Test set worksheet default style commands', () => {+ let univer: Univer;+ let get: Injector['get'];+ let commandService: ICommandService;+ let defaultTheme: RangeThemeStyle;++ beforeEach(() => {+ const testBed = createCommandTestBed();+ univer = testBed.univer;+ get = testBed.get;++ commandService = get(ICommandService);+ commandService.registerCommand(SetWorksheetRangeThemeStyleMutation);+ commandService.registerCommand(DeleteWorksheetRangeThemeStyleMutation);+ commandService.registerCommand(SetWorksheetRangeThemeStyleCommand);+ commandService.registerCommand(DeleteWorksheetRangeThemeStyleCommand);+ commandService.registerCommand(SetStyleCommand);++ const sheetRangeThemeModel = get(SheetRangeThemeModel);+ defaultTheme = sheetRangeThemeModel.getDefaultRangeThemeStyle('default');+ });++ afterEach(() => {+ univer.dispose();+ });++ describe('set worksheet range style', () => {+ it('correct situation', async () => {+ const workbook = get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;+ const worksheet = workbook.getSheetBySheetId('sheet1');+ if (!workbook) throw new Error('This is an error');++ expect(+ await commandService.executeCommand(SetWorksheetRangeThemeStyleCommand.id, {+ unitId: 'test',+ subUnitId: 'sheet1',+ // 'A1:D21'+ range: {+ startRow: 0,+ startColumn: 0,+ endRow: 20,+ endColumn: 3,+ },+ themeName: 'default',+ })+ ).toBeTruthy();++ expect(worksheet?.getCell(0, 0)).toEqual(defaultTheme.getHeaderRowStyle());+ expect(worksheet?.getCell(0, 1)).toEqual(defaultTheme.getHeaderRowStyle());++ expect(worksheet?.getCell(1, 0)).toEqual(defaultTheme.getFirstRowStyle());+ expect(worksheet?.getCell(2, 0)).toEqual(defaultTheme.getSecondRowStyle());++ // undo;+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();+ });++ it('ensure range theme style can not overwrite cell style', async () => {+ const workbook = get(IUniverInstanceService).getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;+ if (!workbook) throw new Error('This is an error');++ await commandService.executeCommand(SetStyleCommand.id, {+ unitId: 'test',+ subUnitId: 'sheet1',+ range: {+ startRow: 0,+ startColumn: 0,+ endRow: 1,+ endColumn: 1,+ },+ style: {+ type: 'bg',+ value: {+ rgb: 'red',+ },+ },+ } as ISetStyleCommandParams<IColorStyle>);++ expect(+ await commandService.executeCommand(SetWorksheetRangeThemeStyleCommand.id, {+ unitId: 'test',+ subUnitId: 'sheet1',+ // 'A1:D21'+ range: {+ startRow: 0,+ startColumn: 0,+ endRow: 20,+ endColumn: 3,+ },+ themeName: 'default',+ })+ ).toBeTruthy();++ const worksheet = workbook.getSheetBySheetId('sheet1');++ expect(worksheet?.getCell(0, 0)).toEqual({+ bg: {+ rgb: 'red',+ },+ });++ expect(worksheet?.getCell(0, 1)).toEqual(defaultTheme.getHeaderRowStyle());+ });+ });+});diff --git a/packages/sheets/src/commands/commands/add-worksheet-range-theme.command.ts b/packages/sheets/src/commands/commands/add-worksheet-range-theme.command.tsnew file mode 100644index 0000000000..5be46f456b--- /dev/null+++ b/packages/sheets/src/commands/commands/add-worksheet-range-theme.command.ts@@ -0,0 +1,53 @@+/**+ * 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 { IAccessor, ICommand } from '@univerjs/core';++import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface';+import {+ CommandType,+ ICommandService,+ IUndoRedoService,+} from '@univerjs/core';+import { SetWorksheetRangeThemeStyleMutation, SetWorksheetRangeThemeStyleMutationFactory } from '../mutations/add-worksheet-range-theme.mutation';+import { DeleteWorksheetRangeThemeStyleMutation } from '../mutations/delete-worksheet-range-theme.mutation';++export const SetWorksheetRangeThemeStyleCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.set-worksheet-range-theme-style',+ handler: (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);++ const { unitId } = params;++ const undoMutationParams = SetWorksheetRangeThemeStyleMutationFactory(accessor, params);++ const result = commandService.syncExecuteCommand(SetWorksheetRangeThemeStyleMutation.id, params);++ if (result) {+ undoRedoService.pushUndoRedo({+ unitID: unitId,+ undoMutations: [{ id: DeleteWorksheetRangeThemeStyleMutation.id, params: undoMutationParams }],+ redoMutations: [{ id: SetWorksheetRangeThemeStyleMutation.id, params }],+ });++ return true;+ }++ return false;+ },+};diff --git a/packages/sheets/src/commands/commands/delete-worksheet-range-theme.command.ts b/packages/sheets/src/commands/commands/delete-worksheet-range-theme.command.tsnew file mode 100644index 0000000000..f7dd5b4ac7--- /dev/null+++ b/packages/sheets/src/commands/commands/delete-worksheet-range-theme.command.ts@@ -0,0 +1,53 @@+/**+ * 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 { IAccessor, ICommand } from '@univerjs/core';++import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface';+import {+ CommandType,+ ICommandService,+ IUndoRedoService,+} from '@univerjs/core';+import { SetWorksheetRangeThemeStyleMutation } from '../mutations/add-worksheet-range-theme.mutation';+import { DeleteWorksheetRangeThemeStyleMutation, DeleteWorksheetRangeThemeStyleMutationFactory } from '../mutations/delete-worksheet-range-theme.mutation';++export const DeleteWorksheetRangeThemeStyleCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.remove-worksheet-range-theme-style',+ handler: (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);++ const { unitId } = params;++ const undoMutationParams = DeleteWorksheetRangeThemeStyleMutationFactory(accessor, params);++ const result = commandService.syncExecuteCommand(DeleteWorksheetRangeThemeStyleMutation.id, params);++ if (result) {+ undoRedoService.pushUndoRedo({+ unitID: unitId,+ undoMutations: [{ id: SetWorksheetRangeThemeStyleMutation.id, params: undoMutationParams }],+ redoMutations: [{ id: DeleteWorksheetRangeThemeStyleMutation.id, params }],+ });++ return true;+ }++ return false;+ },+};diff --git a/packages/sheets/src/commands/commands/register-range-theme.command.ts b/packages/sheets/src/commands/commands/register-range-theme.command.tsnew file mode 100644index 0000000000..054991e487--- /dev/null+++ b/packages/sheets/src/commands/commands/register-range-theme.command.ts@@ -0,0 +1,64 @@+/**+ * 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 { ICommand } from '@univerjs/core';+import type { RangeThemeStyle } from '../../model/range-theme-util';+import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';++import { getSheetCommandTarget } from '../commands/utils/target-util';+import { RegisterWorksheetRangeThemeStyleMutation } from '../mutations/register-range-theme.mutation';+import { UnregisterWorksheetRangeThemeStyleMutation } from '../mutations/unregister-range-theme-style.mutation';++export interface IRegisterWorksheetRangeThemeStyleCommandParams {+ unitId: string;+ rangeThemeStyle: RangeThemeStyle;+}++export const RegisterWorksheetRangeThemeStyleCommand: ICommand<IRegisterWorksheetRangeThemeStyleCommandParams> = {+ id: 'sheet.command.register-worksheet-range-theme-style',+ type: CommandType.COMMAND,+ handler: (accessor, params) => {+ if (!params) {+ return false;+ }+ const { unitId, rangeThemeStyle } = params;+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const target = getSheetCommandTarget(univerInstanceService);+ if (!target) return false;++ const redoParam = {+ unitId,+ themeName: rangeThemeStyle.getName(),+ rangeThemeStyleJson: rangeThemeStyle.toJson(),+ };+ const undoParam = {+ unitId,+ themeName: rangeThemeStyle.getName(),+ };+ const result = commandService.syncExecuteCommand(RegisterWorksheetRangeThemeStyleMutation.id, params);+ if (result) {+ undoRedoService.pushUndoRedo({+ unitID: unitId,+ undoMutations: [{ id: UnregisterWorksheetRangeThemeStyleMutation.id, params: undoParam }],+ redoMutations: [{ id: RegisterWorksheetRangeThemeStyleMutation.id, params: redoParam }],+ });+ }+ return true;+ },+};+diff --git a/packages/sheets/src/commands/commands/unregister-range-theme.command.ts b/packages/sheets/src/commands/commands/unregister-range-theme.command.tsnew file mode 100644index 0000000000..d533e8fc9f--- /dev/null+++ b/packages/sheets/src/commands/commands/unregister-range-theme.command.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 { ICommand } from '@univerjs/core';+import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';++import { SheetRangeThemeModel } from '../../model/range-theme-model';+import { getSheetCommandTarget } from '../commands/utils/target-util';+import { RegisterWorksheetRangeThemeStyleMutation } from '../mutations/register-range-theme.mutation';+import { UnregisterWorksheetRangeThemeStyleMutation } from '../mutations/unregister-range-theme-style.mutation';++export interface IUnregisterWorksheetRangeThemeStyleCommandParams {+ unitId: string;+ themeName: string;+}++export const UnregisterWorksheetRangeThemeStyleCommand: ICommand<IUnregisterWorksheetRangeThemeStyleCommandParams> = {+ id: 'sheet.command.unregister-worksheet-range-theme-style',+ type: CommandType.COMMAND,+ handler: (accessor, params) => {+ if (!params) {+ return false;+ }+ const { unitId, themeName } = params;+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);+ const target = getSheetCommandTarget(univerInstanceService);+ if (!target) return false;++ const redoParam = {+ unitId,+ themeName,+ };+ const undoParam = {+ unitId,+ themeName,+ rangeThemeStyleJson: sheetRangeThemeModel.getRangeThemeStyle(unitId, themeName)?.toJson(),+ };+ const result = commandService.syncExecuteCommand(RegisterWorksheetRangeThemeStyleMutation.id, params);+ if (result) {+ undoRedoService.pushUndoRedo({+ unitID: unitId,+ undoMutations: [{ id: RegisterWorksheetRangeThemeStyleMutation.id, params: undoParam }],+ redoMutations: [{ id: UnregisterWorksheetRangeThemeStyleMutation.id, params: redoParam }],+ });+ }+ return true;+ },+};+diff --git a/packages/sheets/src/commands/commands/utils/selection-utils.ts b/packages/sheets/src/commands/commands/utils/selection-utils.tsindex e0b370118c..aa6a29d440 100644--- a/packages/sheets/src/commands/commands/utils/selection-utils.ts+++ b/packages/sheets/src/commands/commands/utils/selection-utils.ts@@ -14,11 +14,12 @@* limitations under the License.*/-import type { ICellData, IObjectMatrixPrimitiveType, IRange, ISelectionCell, Nullable, Workbook, Worksheet } from '@univerjs/core';+import type { ICellData, IInterceptor, IObjectMatrixPrimitiveType, IRange, ISelectionCell, Nullable, Workbook, Worksheet } from '@univerjs/core';import type { ISelectionWithStyle } from '../../../basics/selection';import type { ISetSelectionsOperationParams } from '../../operations/selection.operation';import { RANGE_TYPE, Rectangle, selectionToArray } from '@univerjs/core';+import { IgnoreRangeThemeInterceptorKey, RangeThemeInterceptorId } from '../../../services/sheet-interceptor/interceptor-const';import { SetSelectionsOperation } from '../../operations/selection.operation';export interface IExpandParams {@@ -234,6 +235,8 @@ export function createRangeIteratorWithSkipFilteredRows(sheet: Worksheet) {};}+const ignoreRangeThemeInterceptorFilter = (interceptor: IInterceptor<unknown, unknown>) => interceptor.id !== RangeThemeInterceptorId;+/*** Copy the styles of a range of cells to another range. Used for insert row and insert column.* @param worksheet@@ -256,7 +259,10 @@ export function copyRangeStyles(const cellValue: IObjectMatrixPrimitiveType<ICellData> = {};for (let row = startRow; row <= endRow; row++) {for (let column = startColumn; column <= endColumn; column++) {- const cell = isRow ? worksheet.getCell(styleRowOrColumn, column) : worksheet.getCell(row, styleRowOrColumn);+ const cell = isRow ?+ worksheet.getCellWithFilteredInterceptors(styleRowOrColumn, column, IgnoreRangeThemeInterceptorKey, ignoreRangeThemeInterceptorFilter)+ : worksheet.getCellWithFilteredInterceptors(row, styleRowOrColumn, IgnoreRangeThemeInterceptorKey, ignoreRangeThemeInterceptorFilter);+if (!cell || !cell.s) {continue;}@@ -281,7 +287,10 @@ export function copyRangeStylesWithoutBorder(const cellValue: IObjectMatrixPrimitiveType<ICellData> = {};for (let row = startRow; row <= endRow; row++) {for (let column = startColumn; column <= endColumn; column++) {- const cell = isRow ? worksheet.getCell(styleRowOrColumn, column) : worksheet.getCell(row, styleRowOrColumn);+ const cell = isRow+ ? worksheet.getCellWithFilteredInterceptors(styleRowOrColumn, column, IgnoreRangeThemeInterceptorKey, ignoreRangeThemeInterceptorFilter)+ : worksheet.getCellWithFilteredInterceptors(row, styleRowOrColumn, IgnoreRangeThemeInterceptorKey, ignoreRangeThemeInterceptorFilter);+if (!cell || !cell.s) {continue;}diff --git a/packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.ts b/packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.tsnew file mode 100644index 0000000000..9e5b133e3c--- /dev/null+++ b/packages/sheets/src/commands/mutations/add-worksheet-range-theme.mutation.ts@@ -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 type { IAccessor, IMutation } from '@univerjs/core';+import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface';+import { CommandType, IUniverInstanceService } from '@univerjs/core';+import { SheetRangeThemeModel } from '../../model/range-theme-model';+import { getSheetCommandTarget, getSheetMutationTarget } from '../commands/utils/target-util';++export const SetWorksheetRangeThemeStyleMutation: IMutation<IWorksheetRangeThemeStyleMutationParams> = {+ id: 'sheet.mutation.set-worksheet-range-theme-style',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const { unitId, subUnitId, range, themeName } = params;+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const target = getSheetCommandTarget(univerInstanceService);+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);+ if (!target) return false;++ sheetRangeThemeModel.registerRangeThemeRule(themeName, { range, unitId, subUnitId });+ return true;+ },+};++export const SetWorksheetRangeThemeStyleMutationFactory = (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => {+ const target = getSheetMutationTarget(accessor.get(IUniverInstanceService), params);+ if (!target) {+ throw new Error('[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!');+ }++ const { worksheet } = target;+ return {+ unitId: params.unitId,+ subUnitId: worksheet.getSheetId(),+ range: params.range,+ themeName: params.themeName,+ };+};diff --git a/packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.ts b/packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.tsnew file mode 100644index 0000000000..d37603fbac--- /dev/null+++ b/packages/sheets/src/commands/mutations/delete-worksheet-range-theme.mutation.ts@@ -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 type { IAccessor, IMutation } from '@univerjs/core';+import type { IWorksheetRangeThemeStyleMutationParams } from '../../basics/interfaces/mutation-interface';+import { CommandType, IUniverInstanceService } from '@univerjs/core';+import { SheetRangeThemeModel } from '../../model/range-theme-model';+import { getSheetCommandTarget, getSheetMutationTarget } from '../commands/utils/target-util';++export const DeleteWorksheetRangeThemeStyleMutation: IMutation<IWorksheetRangeThemeStyleMutationParams> = {+ id: 'sheet.mutation.remove-worksheet-range-theme-style',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const { unitId, subUnitId, range, themeName } = params;+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const target = getSheetCommandTarget(univerInstanceService);+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);+ if (!target) return false;++ sheetRangeThemeModel.removeRangeThemeRule(themeName, { range, unitId, subUnitId });+ return true;+ },+};++export const DeleteWorksheetRangeThemeStyleMutationFactory = (accessor: IAccessor, params: IWorksheetRangeThemeStyleMutationParams) => {+ const target = getSheetMutationTarget(accessor.get(IUniverInstanceService), params);+ if (!target) {+ throw new Error('[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!');+ }++ const { worksheet } = target;+ return {+ unitId: params.unitId,+ subUnitId: worksheet.getSheetId(),+ range: params.range,+ themeName: params.themeName,+ };+};diff --git a/packages/sheets/src/commands/mutations/register-range-theme.mutation.ts b/packages/sheets/src/commands/mutations/register-range-theme.mutation.tsnew file mode 100644index 0000000000..ac6d019a4c--- /dev/null+++ b/packages/sheets/src/commands/mutations/register-range-theme.mutation.ts@@ -0,0 +1,45 @@+/**+ * 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 type { IRangeThemeStyleJSON } from '../../model/range-theme-util';+import { CommandType, IUniverInstanceService } from '@univerjs/core';+import { SheetRangeThemeModel } from '../../model/range-theme-model';+import { RangeThemeStyle } from '../../model/range-theme-util';+import { getSheetCommandTarget } from '../commands/utils/target-util';++export interface IRegisterWorksheetRangeThemeStyleMutationParams {+ unitId: string;+ themeName: string;+ rangeThemeStyleJson: IRangeThemeStyleJSON;+}++export const RegisterWorksheetRangeThemeStyleMutation: IMutation<IRegisterWorksheetRangeThemeStyleMutationParams> = {+ id: 'sheet.mutation.register-worksheet-range-theme-style',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const { unitId, rangeThemeStyleJson, themeName } = params;+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const target = getSheetCommandTarget(univerInstanceService);+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);+ if (!target) return false;++ const rangeThemeStyle = new RangeThemeStyle(themeName, rangeThemeStyleJson);+ sheetRangeThemeModel.registerRangeThemeStyle(unitId, rangeThemeStyle);+ return true;+ },+};+diff --git a/packages/sheets/src/commands/mutations/unregister-range-theme-style.mutation.ts b/packages/sheets/src/commands/mutations/unregister-range-theme-style.mutation.tsnew file mode 100644index 0000000000..43ba0a58ff--- /dev/null+++ b/packages/sheets/src/commands/mutations/unregister-range-theme-style.mutation.ts@@ -0,0 +1,41 @@+/**+ * 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, IUniverInstanceService } from '@univerjs/core';+import { SheetRangeThemeModel } from '../../model/range-theme-model';+import { getSheetCommandTarget } from '../commands/utils/target-util';++export interface IUnregisterWorksheetRangeThemeStyleMutationParams {+ unitId: string;+ themeName: string;+}++export const UnregisterWorksheetRangeThemeStyleMutation: IMutation<IUnregisterWorksheetRangeThemeStyleMutationParams> = {+ id: 'sheet.mutation.unregister-worksheet-range-theme-style',+ type: CommandType.MUTATION,+ handler: (accessor, params) => {+ const { unitId, themeName } = params;+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const target = getSheetCommandTarget(univerInstanceService);+ const sheetRangeThemeModel = accessor.get(SheetRangeThemeModel);+ if (!target) return false;++ sheetRangeThemeModel.unregisterRangeThemeStyle(unitId, themeName);+ return true;+ },+};+diff --git a/packages/sheets/src/controllers/basic-worksheet.controller.ts b/packages/sheets/src/controllers/basic-worksheet.controller.tsindex efdd232348..99fd7f0349 100644--- a/packages/sheets/src/controllers/basic-worksheet.controller.ts+++ b/packages/sheets/src/controllers/basic-worksheet.controller.ts@@ -20,6 +20,7 @@ import { DataSyncPrimaryController } from '@univerjs/rpc';import { AddRangeProtectionCommand } from '../commands/commands/add-range-protection.command';import { AddWorksheetProtectionCommand } from '../commands/commands/add-worksheet-protection.command';+import { SetWorksheetRangeThemeStyleCommand } from '../commands/commands/add-worksheet-range-theme.command';import { ClearSelectionAllCommand } from '../commands/commands/clear-selection-all.command';import { ClearSelectionContentCommand } from '../commands/commands/clear-selection-content.command';import { ClearSelectionFormatCommand } from '../commands/commands/clear-selection-format.command';@@ -28,6 +29,7 @@ import { DeleteRangeMoveLeftCommand } from '../commands/commands/delete-range-moimport { DeleteRangeMoveUpCommand } from '../commands/commands/delete-range-move-up.command';import { DeleteRangeProtectionCommand } from '../commands/commands/delete-range-protection.command';import { DeleteWorksheetProtectionCommand } from '../commands/commands/delete-worksheet-protection.command';+import { DeleteWorksheetRangeThemeStyleCommand } from '../commands/commands/delete-worksheet-range-theme.command';import { InsertDefinedNameCommand } from '../commands/commands/insert-defined-name.command';import { InsertRangeMoveDownCommand } from '../commands/commands/insert-range-move-down.command';import { InsertRangeMoveRightCommand } from '../commands/commands/insert-range-move-right.command';@@ -44,6 +46,7 @@ import {import { InsertSheetCommand } from '../commands/commands/insert-sheet.command';import { MoveRangeCommand } from '../commands/commands/move-range.command';import { MoveColsCommand, MoveRowsCommand } from '../commands/commands/move-rows-cols.command';+import { RegisterWorksheetRangeThemeStyleCommand } from '../commands/commands/register-range-theme.command';import { RemoveDefinedNameCommand } from '../commands/commands/remove-defined-name.command';import { RemoveColByRangeCommand, RemoveColCommand, RemoveRowByRangeCommand, RemoveRowCommand } from '../commands/commands/remove-row-col.command';import { RemoveSheetCommand } from '../commands/commands/remove-sheet.command';@@ -103,23 +106,27 @@ import { SetWorksheetShowCommand } from '../commands/commands/set-worksheet-showimport { SplitTextToColumnsCommand } from '../commands/commands/split-text-to-columns.command';import { ToggleCellCheckboxCommand } from '../commands/commands/toggle-checkbox.command';import { ToggleGridlinesCommand } from '../commands/commands/toggle-gridlines.command';+import { UnregisterWorksheetRangeThemeStyleCommand } from '../commands/commands/unregister-range-theme.command';import { AddRangeProtectionMutation } from '../commands/mutations/add-range-protection.mutation';import { AddWorksheetMergeMutation } from '../commands/mutations/add-worksheet-merge.mutation';import { AddWorksheetProtectionMutation } from '../commands/mutations/add-worksheet-protection.mutation';+import { SetWorksheetRangeThemeStyleMutation } from '../commands/mutations/add-worksheet-range-theme.mutation';import { DeleteRangeProtectionMutation } from '../commands/mutations/delete-range-protection.mutation';import { DeleteWorksheetProtectionMutation } from '../commands/mutations/delete-worksheet-protection.mutation';+import { DeleteWorksheetRangeThemeStyleMutation } from '../commands/mutations/delete-worksheet-range-theme.mutation';import { EmptyMutation } from '../commands/mutations/empty.mutation';+import { InsertColMutation, InsertRowMutation } from '../commands/mutations/insert-row-col.mutation';import { InsertSheetMutation } from '../commands/mutations/insert-sheet.mutation';import { MoveRangeMutation } from '../commands/mutations/move-range.mutation';+import { MoveColsMutation, MoveRowsMutation } from '../commands/mutations/move-rows-cols.mutation';import { RemoveNumfmtMutation, SetNumfmtMutation } from '../commands/mutations/numfmt-mutation';+import { RegisterWorksheetRangeThemeStyleMutation } from '../commands/mutations/register-range-theme.mutation';import { RemoveColMutation, RemoveRowMutation } from '../commands/mutations/remove-row-col.mutation';-import { RemoveSheetMutation } from '../commands/mutations/remove-sheet.mutation';import { RemoveWorksheetMergeMutation } from '../commands/mutations/remove-worksheet-merge.mutation';import { ReorderRangeMutation } from '../commands/mutations/reorder-range.mutation';-import { SetColDataMutation } from '../commands/mutations/set-col-data.mutation';import { SetColHiddenMutation, SetColVisibleMutation } from '../commands/mutations/set-col-visible.mutation';import { SetFrozenMutation } from '../commands/mutations/set-frozen.mutation';@@ -143,6 +150,7 @@ import {SetWorksheetRowIsAutoHeightMutation,} from '../commands/mutations/set-worksheet-row-height.mutation';import { ToggleGridlinesMutation } from '../commands/mutations/toggle-gridlines.mutation';+import { UnregisterWorksheetRangeThemeStyleMutation } from '../commands/mutations/unregister-range-theme-style.mutation';import { ScrollToCellOperation } from '../commands/operations/scroll-to-cell.operation';import { SetSelectionsOperation } from '../commands/operations/selection.operation';import { SetWorksheetActiveOperation } from '../commands/operations/set-worksheet-active.operation';@@ -309,6 +317,18 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetWorksheetDefaultStyleCommand,SplitTextToColumnsCommand,++ // range theme++ DeleteWorksheetRangeThemeStyleMutation,+ SetWorksheetRangeThemeStyleMutation,+ UnregisterWorksheetRangeThemeStyleMutation,+ RegisterWorksheetRangeThemeStyleMutation,+ UnregisterWorksheetRangeThemeStyleCommand,+ RegisterWorksheetRangeThemeStyleCommand,+ SetWorksheetRangeThemeStyleCommand,+ DeleteWorksheetRangeThemeStyleCommand,+].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}diff --git a/packages/sheets/src/facade/f-range.ts b/packages/sheets/src/facade/f-range.tsindex bd8f6ffdc7..776e50911d 100644--- a/packages/sheets/src/facade/f-range.ts+++ b/packages/sheets/src/facade/f-range.ts@@ -19,7 +19,7 @@ import type { ISetHorizontalTextAlignCommandParams, ISetStyleCommandParams, ISetimport type { FHorizontalAlignment, FVerticalAlignment } from './utils';import { BooleanNumber, Dimension, FBaseInitialable, ICommandService, Inject, Injector, Rectangle, WrapStrategy } from '@univerjs/core';import { FormulaDataModel, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula';-import { addMergeCellsUtil, getAddMergeMutationRangeByType, RemoveWorksheetMergeCommand, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SplitTextToColumnsCommand } from '@univerjs/sheets';+import { addMergeCellsUtil, DeleteWorksheetRangeThemeStyleCommand, getAddMergeMutationRangeByType, RemoveWorksheetMergeCommand, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetRangeThemeStyleCommand, SheetRangeThemeService, SplitTextToColumnsCommand } from '@univerjs/sheets';import { FWorkbook } from './f-workbook';import { covertCellValue, covertCellValues, transformCoreHorizontalAlignment, transformCoreVerticalAlignment, transformFacadeHorizontalAlignment, transformFacadeVerticalAlignment } from './utils';@@ -774,4 +774,72 @@ export class FRange extends FBaseInitialable {treatMultipleDelimitersAsOne,});}++ /**+ * Set the theme style for the range.+ * @param {string|undefined} themeName The name of the theme style to apply.If a undefined value is passed, the theme style will be removed if it exist.+ * @example+ * ```ts+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const fRange = fWorksheet.getRange('A1:E20');+ * fRange.useThemeStyle('default');+ * ```+ */+ useThemeStyle(themeName: string | undefined): void {+ if (themeName === null || themeName === undefined) {+ const usedThemeName = this.getUsedThemeStyle();+ if (usedThemeName) {+ this.removeThemeStyle(usedThemeName);+ }+ } else {+ this._commandService.executeCommand(SetWorksheetRangeThemeStyleCommand.id, {+ unitId: this._workbook.getUnitId(),+ subUnitId: this._worksheet.getSheetId(),+ range: this._range,+ themeName,+ });+ }+ }++ /**+ * Remove the theme style for the range.+ * @param {string} themeName The name of the theme style to remove.+ * @example+ * ```ts+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const fRange = fWorksheet.getRange('A1:E20');+ * fRange.removeThemeStyle('default');+ * ```+ */+ removeThemeStyle(themeName: string): void {+ this._commandService.executeCommand(DeleteWorksheetRangeThemeStyleCommand.id, {+ unitId: this._workbook.getUnitId(),+ subUnitId: this._worksheet.getSheetId(),+ range: this._range,+ themeName,+ });+ }++ /**+ * Gets the theme style applied to the range.+ * @returns {string | undefined} The name of the theme style applied to the range or not exist.+ * @example+ * ```ts+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const fRange = fWorksheet.getRange('A1:E20');+ * fRange.useThemeStyle('default');+ * const themeStyle = fRange.getUsedThemeStyle();+ * console.log(themeStyle); // 'default'+ * ```+ */+ getUsedThemeStyle(): string | undefined {+ return this._injector.get(SheetRangeThemeService).getAppliedRangeThemeStyle({+ unitId: this._workbook.getUnitId(),+ subUnitId: this._worksheet.getSheetId(),+ range: this._range,+ });+ }}diff --git a/packages/sheets/src/facade/f-workbook.ts b/packages/sheets/src/facade/f-workbook.tsindex 0dd7dcf82b..d74c3bb538 100644--- a/packages/sheets/src/facade/f-workbook.ts+++ b/packages/sheets/src/facade/f-workbook.ts@@ -16,10 +16,11 @@import type { CommandListener, ICommandInfo, IDisposable, IRange, IWorkbookData, LocaleType, Workbook } from '@univerjs/core';import type { ISetDefinedNameMutationParam } from '@univerjs/engine-formula';-import type { ISetSelectionsOperationParams, ISheetCommandSharedParams } from '@univerjs/sheets';+import type { ISetSelectionsOperationParams, ISheetCommandSharedParams, RangeThemeStyle } from '@univerjs/sheets';import { FBaseInitialable, ICommandService, ILogService, Inject, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService, mergeWorksheetSnapshotWithDefault, RedoCommand, toDisposable, UndoCommand, UniverInstanceType } from '@univerjs/core';+import { IDefinedNamesService } from '@univerjs/engine-formula';-import { CopySheetCommand, getPrimaryForRange, InsertSheetCommand, RemoveSheetCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetDefinedNameCommand, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetOrderCommand, SheetsSelectionsService, WorkbookEditablePermission } from '@univerjs/sheets';+import { CopySheetCommand, getPrimaryForRange, InsertSheetCommand, RegisterWorksheetRangeThemeStyleCommand, RemoveSheetCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetDefinedNameCommand, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetOrderCommand, SheetRangeThemeService, SheetsSelectionsService, UnregisterWorksheetRangeThemeStyleCommand, WorkbookEditablePermission } from '@univerjs/sheets';import { FDefinedName, FDefinedNameBuilder } from './f-defined-name';import { FPermission } from './f-permission';import { FRange } from './f-range';@@ -744,10 +745,61 @@ export class FWorkbook extends FBaseInitialable {* const builder = activeSpreadsheet.getDefinedName('MyDefinedName').toBuilder();* builder.setRef('Sheet1!A2').setName('MyDefinedName1').build();* activeSpreadsheet.updateDefinedNameBuilder(param);- ** ```*/updateDefinedNameBuilder(param: ISetDefinedNameMutationParam): void {this._commandService.syncExecuteCommand(SetDefinedNameCommand.id, param);}++ /**+ * Gets the registered range themes.+ * @returns {string[]} The name list of registered range themes.+ * @example+ * ```ts+ * // The code below gets the registered range themes+ * const activeSpreadsheet = univerAPI.getActiveWorkbook();+ * const themes = activeSpreadsheet.getRegisteredRangeThemes();+ * console.log(themes);+ * ```+ */+ getRegisteredRangeThemes(): string[] {+ return this._injector.get(SheetRangeThemeService).getRegisteredRangeThemes();+ }++ /**+ * Register a custom range theme style.+ * @example+ * ```ts+ * // import {RangeThemeStyle} from '@univerjs/sheets';+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const rangeThemeStyle = new RangeThemeStyle('MyTheme');+ * rangeThemeStyle.setSecondRowStyle({+ * bg: {+ * rgb: 'rgb(214,231,241)',+ * },+ * });+ * fWorkbook.registerRangeTheme(rangeThemeStyle);+ * ```+ */+ registerRangeTheme(rangeThemeStyle: RangeThemeStyle): void {+ this._commandService.syncExecuteCommand(RegisterWorksheetRangeThemeStyleCommand.id, {+ unitId: this.getId(),+ rangeThemeStyle,+ });+ }++ /**+ * Unregister a custom range theme style.+ * @example+ * ```ts+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * fWorkbook.unregisterRangeTheme('MyTheme');+ * ```+ */+ unregisterRangeTheme(themeName: string): void {+ this._commandService.syncExecuteCommand(UnregisterWorksheetRangeThemeStyleCommand.id, {+ unitId: this.getId(),+ themeName,+ });+ }}diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.tsindex 42c29640e4..40852622cc 100644--- a/packages/sheets/src/index.ts+++ b/packages/sheets/src/index.ts@@ -29,6 +29,7 @@ export {type IRemoveRowsMutationParams,type IRemoveSheetMutationParams,type IRemoveWorksheetMergeMutationParams,+ type IWorksheetRangeThemeStyleMutationParams,} from './basics/interfaces/mutation-interface';export {convertPrimaryWithCoordToPrimary,@@ -45,6 +46,7 @@ export { createTopMatrixFromMatrix, createTopMatrixFromRanges, findAllRectangle,export { type IUniverSheetsConfig } from './controllers/config.schema';export { MAX_CELL_PER_SHEET_KEY } from './controllers/config/config';export { BorderStyleManagerService, type IBorderInfo } from './services/border-style-manager.service';+export { SheetRangeThemeService } from './services/range-theme-service';export * from './services/permission/permission-point';export { WorksheetPermissionService } from './services/permission/worksheet-permission/worksheet-permission.service';export { WorkbookPermissionService } from './services/permission/workbook-permission/workbook-permission.service';@@ -176,6 +178,7 @@ export { getInsertRangeMutations, getRemoveRangeMutations } from './commands/utiexport { handleInsertRangeMutation } from './commands/utils/handle-range-mutation';export { type ISheetCommandSharedParams } from './commands/utils/interface';export { copyRangeStyles } from './commands/commands/utils/selection-utils';+export { RangeThemeStyle } from './model/range-theme-util';// #region - all commands@@ -190,6 +193,8 @@ export {AddWorksheetMergeHorizontalCommand,AddWorksheetMergeVerticalCommand,} from './commands/commands/add-worksheet-merge.command';+export { SetWorksheetRangeThemeStyleCommand } from './commands/commands/add-worksheet-range-theme.command';+export { DeleteWorksheetRangeThemeStyleCommand } from './commands/commands/delete-worksheet-range-theme.command';export { ClearSelectionAllCommand } from './commands/commands/clear-selection-all.command';export { ClearSelectionContentCommand } from './commands/commands/clear-selection-content.command';export { ClearSelectionFormatCommand } from './commands/commands/clear-selection-format.command';@@ -321,6 +326,13 @@ export { SetWorksheetShowCommand } from './commands/commands/set-worksheet-show.export { SplitTextToColumnsCommand } from './commands/commands/split-text-to-columns.command';export type { ISplitTextToColumnsCommandParams } from './commands/commands/split-text-to-columns.command';+export { UnregisterWorksheetRangeThemeStyleCommand } from './commands/commands/unregister-range-theme.command';+export type { IUnregisterWorksheetRangeThemeStyleCommandParams } from './commands/commands/unregister-range-theme.command';+export { RegisterWorksheetRangeThemeStyleCommand } from './commands/commands/register-range-theme.command';+export type { IRegisterWorksheetRangeThemeStyleCommandParams } from './commands/commands/register-range-theme.command';+export { type IRegisterWorksheetRangeThemeStyleMutationParams, RegisterWorksheetRangeThemeStyleMutation } from './commands/mutations/register-range-theme.mutation';+export { type IUnregisterWorksheetRangeThemeStyleMutationParams, UnregisterWorksheetRangeThemeStyleMutation } from './commands/mutations/unregister-range-theme-style.mutation';+export type { ISetWorksheetShowCommandParams } from './commands/commands/set-worksheet-show.command';export { AddRangeProtectionMutation, FactoryAddRangeProtectionMutation, type IAddRangeProtectionMutationParams } from './commands/mutations/add-range-protection.mutation';export { SetProtectionCommand } from './commands/commands/set-protection.command';@@ -396,6 +408,8 @@ export {export { type ISetWorksheetHideMutationParams, SetWorksheetHideMutation } from './commands/mutations/set-worksheet-hide.mutation';export { type ISetWorksheetNameMutationParams, SetWorksheetNameMutation } from './commands/mutations/set-worksheet-name.mutation';export { type ISetWorksheetOrderMutationParams, SetWorksheetOrderMutation } from './commands/mutations/set-worksheet-order.mutation';+export { SetWorksheetRangeThemeStyleMutation, SetWorksheetRangeThemeStyleMutationFactory } from './commands/mutations/add-worksheet-range-theme.mutation';+export { DeleteWorksheetRangeThemeStyleMutation, DeleteWorksheetRangeThemeStyleMutationFactory } from './commands/mutations/delete-worksheet-range-theme.mutation';export { SetWorksheetPermissionPointsMutation } from './commands/mutations/set-worksheet-permission-points.mutation';export type { ISetWorksheetPermissionPointsMutationParams } from './commands/mutations/set-worksheet-permission-points.mutation';export { SetWorksheetProtectionMutation } from './commands/mutations/set-worksheet-protection.mutation';diff --git a/packages/sheets/src/model/range-theme-model.ts b/packages/sheets/src/model/range-theme-model.tsnew file mode 100644index 0000000000..4b4e3dde0c--- /dev/null+++ b/packages/sheets/src/model/range-theme-model.ts@@ -0,0 +1,304 @@+/**+ * 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, IRange, Nullable } from '@univerjs/core';+import type { IRangeThemeStyleItem, IRangeThemeStyleJSON } from './range-theme-util';+import { Disposable, generateRandomId, Inject, InterceptorEffectEnum, IResourceManagerService, RTree, UniverInstanceType } from '@univerjs/core';+import { INTERCEPTOR_POINT, RangeThemeInterceptorId } from '../services/sheet-interceptor/interceptor-const';+import { SheetInterceptorService } from '../services/sheet-interceptor/sheet-interceptor.service';+import { RangeThemeStyle } from './range-theme-util';++import { buildInThemes } from './range-themes/build-in-theme.factory';+import { defaultRangeThemeStyle } from './range-themes/default';++export interface IRangeThemeRangeInfo {+ range: IRange;+ unitId: string;+ subUnitId: string;+}++export interface IRangeThemeStyleRule {+ rangeInfo: IRangeThemeRangeInfo;+ themeName: string;+}++interface ISheetRangeThemeModelJSON {+ rangeThemeStyleRuleMap: Record<string, IRangeThemeStyleRule>;+ rangeThemeStyleMapJson: Record<string, IRangeThemeStyleJSON>;+}++const SHEET_RANGE_THEME_MODEL_PLUGIN = 'SHEET_RANGE_THEME_MODEL_PLUGIN';++export class SheetRangeThemeModel extends Disposable {+ private _rangeThemeStyleMap: Map<string, Map<string, RangeThemeStyle>> = new Map();+ private _rangeThemeStyleRuleMap: Map<string, Map<string, IRangeThemeStyleRule>> = new Map();+ private _rTreeCollection: Map<string, RTree> = new Map();+ private _defaultRangeThemeMap: Map<string, RangeThemeStyle> = new Map();+ constructor(+ @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,+ @Inject(IResourceManagerService) private _resourceManagerService: IResourceManagerService+ ) {+ super();+ this._registerIntercept();+ this._initSnapshot();+ this._initDefaultTheme();+ }++ private _initDefaultTheme() {+ this.registerDefaultRangeTheme(defaultRangeThemeStyle);+ for (const theme of buildInThemes) {+ this.registerDefaultRangeTheme(theme);+ }+ }++ private _ensureRangeThemeStyleMap(unitId: string) {+ if (!this._rangeThemeStyleMap.has(unitId)) {+ this._rangeThemeStyleMap.set(unitId, new Map());+ }+ return this._rangeThemeStyleMap.get(unitId)!;+ }++ private _ensureRangeThemeStyleRuleMap(unitId: string) {+ if (!this._rangeThemeStyleRuleMap.has(unitId)) {+ this._rangeThemeStyleRuleMap.set(unitId, new Map());+ }+ return this._rangeThemeStyleRuleMap.get(unitId)!;+ }++ private _ensureRTreeCollection(unitId: string) {+ if (!this._rTreeCollection.has(unitId)) {+ this._rTreeCollection.set(unitId, new RTree());+ }+ return this._rTreeCollection.get(unitId)!;+ }++ public getDefaultRangeThemeStyle(name: string): RangeThemeStyle {+ return this._defaultRangeThemeMap.get(name)!;+ }++ /**+ * Register range theme styles+ * @param {string} themeName+ * @param {IRangeThemeRangeInfo} rangeInfo+ */+ registerRangeThemeRule(themeName: string, rangeInfo: IRangeThemeRangeInfo): void {+ const { unitId, subUnitId, range } = rangeInfo;+ const id = generateRandomId();+ const ruleMap = this._ensureRangeThemeStyleRuleMap(unitId);+ const rTreeCollection = this._ensureRTreeCollection(unitId);+ ruleMap.set(id, { rangeInfo, themeName });+ rTreeCollection.insert({ unitId, sheetId: subUnitId, range, id });+ }++ getRegisteredRangeThemeStyle(rangeInfo: IRangeThemeRangeInfo): string | undefined {+ const { unitId, subUnitId, range } = rangeInfo;+ const rTreeCollection = this._ensureRTreeCollection(unitId);+ const themes = Array.from(rTreeCollection.bulkSearch([{ unitId, sheetId: subUnitId, range }]));+ if (themes[0]) {+ const themeRuleMap = this._ensureRangeThemeStyleRuleMap(unitId);+ const themeRule = themeRuleMap.get(themes[0] as string);+ if (themeRule) {+ return themeRule.themeName;+ }+ }+ return undefined;+ }++ removeRangeThemeRule(themeName: string, rangeInfo: IRangeThemeRangeInfo): void {+ const { unitId, subUnitId, range } = rangeInfo;+ const rTreeCollection = this._ensureRTreeCollection(unitId);+ const themes = Array.from(rTreeCollection.bulkSearch([{ unitId, sheetId: subUnitId, range }]));+ if (themes[0]) {+ const themeRuleMap = this._ensureRangeThemeStyleRuleMap(unitId);+ const themeRule = themeRuleMap.get(themes[0] as string);+ if (themeRule && themeRule.themeName === themeName) {+ themeRuleMap.delete(themes[0] as string);+ rTreeCollection.remove({ unitId, sheetId: subUnitId, range, id: themes[0] as string });+ }+ }+ }++ registerDefaultRangeTheme(rangeThemeStyle: RangeThemeStyle): void {+ this._defaultRangeThemeMap.set(rangeThemeStyle.getName(), rangeThemeStyle);+ }++ getRegisteredRangeThemes(): string[] {+ return Array.from(this._defaultRangeThemeMap.keys());+ }++ /**+ * Register custom range theme style.+ * @param {string} unitId The unit id.+ * @param {RangeThemeStyle} rangeThemeStyle The range theme style.+ */+ registerRangeThemeStyle(unitId: string, rangeThemeStyle: RangeThemeStyle): void {+ this._ensureRangeThemeStyleMap(unitId).set(rangeThemeStyle.getName(), rangeThemeStyle);+ }++ /**+ * Unregister custom range theme style.+ * @param {string} unitId The unit id.+ * @param {string} name The name of the range theme style.+ */+ unregisterRangeThemeStyle(unitId: string, name: string): void {+ this._ensureRangeThemeStyleMap(unitId).delete(name);+ }++ /**+ * Gets all custom register themes+ * @return {string[]} The array of all custom registered themes.+ */+ getALLRegisteredTheme(): string[] {+ return Array.from(this._rangeThemeStyleMap.keys());+ }++ getRangeThemeStyle(unitId: string, name: string): RangeThemeStyle {+ if (this._defaultRangeThemeMap.has(name)) {+ return this._defaultRangeThemeMap.get(name)!;+ }+ return this._ensureRangeThemeStyleMap(unitId).get(name)!;+ }++ public getCellStyle(unitId: string, subUnitId: string, row: number, col: number): Nullable<IRangeThemeStyleItem> {+ const range = { startRow: row, startColumn: col, endRow: row, endColumn: col };+ const rTreeCollection = this._ensureRTreeCollection(unitId);+ const themes = Array.from(rTreeCollection.bulkSearch([{ unitId, sheetId: subUnitId, range }]));+ if (themes[0]) {+ const themeRuleMap = this._ensureRangeThemeStyleRuleMap(unitId);+ const themeRule = themeRuleMap.get(themes[0] as string);+ if (themeRule) {+ const { rangeInfo, themeName } = themeRule;+ const offsetRow = row - rangeInfo.range.startRow;+ const offsetCol = col - rangeInfo.range.startColumn;+ const theme = this.getRangeThemeStyle(unitId, themeName);+ return theme.getStyle(offsetRow, offsetCol, row === rangeInfo.range.endRow, col === rangeInfo.range.endColumn);+ }+ }+ return undefined;+ }++ private _registerIntercept(): void {+ this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {+ id: RangeThemeInterceptorId,+ effect: InterceptorEffectEnum.Style,+ handler: (cell, context, next) => {+ const { row, col, unitId, subUnitId } = context;++ const style = this.getCellStyle(unitId, subUnitId, row, col);++ if (style) {+ const newCell: ICellDataForSheetInterceptor = { ...cell };+ newCell.themeStyle = style;+ return next(newCell);+ }++ return next(cell);+ },+ }));+ }++ toJson(unitId: string) {+ // deserialize registered range theme style rule+ const ruleMap = this._ensureRangeThemeStyleRuleMap(unitId);+ // deserialize custom range theme style+ const rangeThemeStyleMap = this._ensureRangeThemeStyleMap(unitId);++ if (rangeThemeStyleMap.size === 0 && ruleMap.size === 0) {+ return '{}';+ }++ const rangeThemeStyleRuleMap: Record<string, IRangeThemeStyleRule> = {};+ ruleMap.forEach((value, key) => {+ rangeThemeStyleRuleMap[key] = value;+ });++ const rangeThemeStyleMapJson: Record<string, IRangeThemeStyleJSON> = {};+ rangeThemeStyleMap.forEach((value, key) => {+ rangeThemeStyleMapJson[key] = value.toJson();+ });++ return JSON.stringify({+ rangeThemeStyleRuleMap,+ rangeThemeStyleMapJson,+ });+ }++ fromJSON(json: ISheetRangeThemeModelJSON) {+ const { rangeThemeStyleRuleMap, rangeThemeStyleMapJson } = json;++ this._rangeThemeStyleMap.clear();+ this._rangeThemeStyleRuleMap.clear();+ this._rTreeCollection.clear();+ if (!rangeThemeStyleRuleMap || !rangeThemeStyleMapJson) {+ return;+ }+ Object.keys(rangeThemeStyleRuleMap).forEach((key) => {+ const ruleMap = rangeThemeStyleRuleMap[key];+ const { themeName, rangeInfo } = ruleMap;+ this.registerRangeThemeRule(themeName, rangeInfo);+ const rTreeCollection = this._ensureRTreeCollection(rangeInfo.unitId);+ rTreeCollection.insert({ unitId: key, sheetId: rangeInfo.subUnitId, range: rangeInfo.range, id: key });+ });++ Object.keys(rangeThemeStyleMapJson).forEach((key) => {+ const styleMap = rangeThemeStyleMapJson[key];+ const style = new RangeThemeStyle(styleMap.name);+ style.fromJson(styleMap);+ this._ensureRangeThemeStyleMap(key).set(style.getName(), style);+ });+ }++ deleteUnitId(unitId: string) {+ this._rangeThemeStyleMap.delete(unitId);+ this._rangeThemeStyleRuleMap.delete(unitId);+ this._rTreeCollection.delete(unitId);+ }++ private _initSnapshot(): void {+ this.disposeWithMe(this._resourceManagerService.registerPluginResource({+ toJson: (unitId: string) => {+ return this.toJson(unitId);+ },+ parseJson: (json: string) => {+ if (!json) {+ return {};+ }+ try {+ return JSON.parse(json);+ // eslint-disable-next-line unused-imports/no-unused-vars+ } catch (error) {+ return {};+ }+ },+ businesses: [UniverInstanceType.UNIVER_SHEET],+ pluginName: SHEET_RANGE_THEME_MODEL_PLUGIN,+ onLoad: (_unitId, resources) => {+ this.fromJSON(resources);+ },+ onUnLoad: (unitId) => {+ this.deleteUnitId(unitId);+ },+ }));+ }++ override dispose(): void {+ super.dispose();+ this._rangeThemeStyleMap.clear();+ this._rangeThemeStyleRuleMap.clear();+ this._defaultRangeThemeMap.clear();+ this._rTreeCollection.clear();+ }+}diff --git a/packages/sheets/src/model/range-theme-util.ts b/packages/sheets/src/model/range-theme-util.tsnew file mode 100644index 0000000000..ebb3b4d4fb--- /dev/null+++ b/packages/sheets/src/model/range-theme-util.ts@@ -0,0 +1,432 @@+/**+ * 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';++export type IRangeThemeStyleItem = Pick<IStyleData, 'bg' | 'ol' | 'bd' | 'cl' | 'ht' | 'vt' | 'bl'>;++export interface IRangeThemeStyleJSON {+ name: string;+ wholeStyle?: IRangeThemeStyleItem;+ headerRowStyle?: IRangeThemeStyleItem;+ headerColumnStyle?: IRangeThemeStyleItem;+ firstRowStyle?: IRangeThemeStyleItem;+ secondRowStyle?: IRangeThemeStyleItem;+ lastRowStyle?: IRangeThemeStyleItem;+ firstColumnStyle?: IRangeThemeStyleItem;+ secondColumnStyle?: IRangeThemeStyleItem;+ lastColumnStyle?: IRangeThemeStyleItem;+}++const serializeRangeStyle = (style: IRangeThemeStyleItem) => {+ const result = {} as IRangeThemeStyleItem;+ if (style.bg) {+ result.bg = { ...style.bg };+ }+ if (style.ol) {+ result.ol = { ...style.ol };+ }+ if (style.bd) {+ result.bd = { ...style.bd };+ }+ if (style.cl) {+ result.cl = { ...style.cl };+ }+ if (style.ht) {+ result.ht = style.ht;+ }+ if (style.vt) {+ result.vt = style.vt;+ }+ // the bl type is BooleanNumber, may be 0+ if (style.bl !== undefined) {+ result.bl = style.bl;+ }+ return result;+};++export function composeStyles(styles: IStyleData[]): IRangeThemeStyleItem {+ const composedStyle: IRangeThemeStyleItem = {};+ if (styles.length === 1) {+ return styles[0];+ }++ for (const style of styles) {+ if (style.bg) {+ composedStyle.bg = style.bg;+ }+ if (style.ol) {+ composedStyle.ol = style.ol;+ }+ if (style.bd) {+ composedStyle.bd = { ...composedStyle.bd, ...style.bd };+ }+ if (style.cl) {+ composedStyle.cl = style.cl;+ }+ if (style.ht) {+ composedStyle.ht = style.ht;+ }+ if (style.vt) {+ composedStyle.vt = style.vt;+ }+ if (style.bl !== undefined) {+ composedStyle.bl = style.bl;+ }+ }++ return composedStyle;+}++const STYLE_MAP = {+ wholeStyle: 1,+ headerRowStyle: 2,+ headerColumnStyle: 4,+ firstRowStyle: 8,+ secondRowStyle: 16,+ lastRowStyle: 32,+ firstColumnStyle: 128,+ secondColumnStyle: 256,+ lastColumnStyle: 512,+};++/**+ * Range theme style+ * @description The range theme style is used to set the style of the range.This class is used to create a build-in theme style or a custom theme style.+ */+export class RangeThemeStyle {+ private _name: string;+ /**+ * @property {Nullable<IRangeThemeStyleItem>} wholeStyle effect for the whole range.+ */+ wholeStyle: Nullable<IRangeThemeStyleItem> = null;++ /**+ * @property {Nullable<IRangeThemeStyleItem>} headerRowStyle effect for the header row.+ */+ headerRowStyle: Nullable<IRangeThemeStyleItem> = null;+ /**+ * @property {Nullable<IRangeThemeStyleItem>} headerColumnStyle effect for the header column.+ */+ headerColumnStyle: Nullable<IRangeThemeStyleItem> = null;++ /**+ * @property {Nullable<IRangeThemeStyleItem>} firstRowStyle effect for the first row.+ */+ firstRowStyle: Nullable<IRangeThemeStyleItem> = null;+ /**+ * @property {Nullable<IRangeThemeStyleItem>} secondRowStyle effect for the second row.+ */+ secondRowStyle: Nullable<IRangeThemeStyleItem> = null;+ /**+ * @property {Nullable<IRangeThemeStyleItem>} lastRowStyle effect for the last row.+ */+ lastRowStyle: Nullable<IRangeThemeStyleItem> = null;+ /**+ * @property {Nullable<IRangeThemeStyleItem>} effect for the first column.+ */+ firstColumnStyle: Nullable<IRangeThemeStyleItem> = null;+ /**+ * @property {Nullable<IRangeThemeStyleItem>} effect for the second column.+ */+ secondColumnStyle: Nullable<IRangeThemeStyleItem> = null;+ /**+ * @property {Nullable<IRangeThemeStyleItem>} effect for the last column.+ */+ lastColumnStyle: Nullable<IRangeThemeStyleItem> = null;++ /**+ * @property {Nullable<IRangeThemeStyleItem>} quickly get merge style+ */+ private _mergeCacheMap: Map<number, IRangeThemeStyleItem> = new Map();+ /**+ * @constructor+ * @param {string} name The name of the range theme style, it used to identify the range theme style.+ * @param {IRangeThemeStyleJSON} [options] The options to initialize the range theme style.+ */+ constructor(name: string, options?: Omit<IRangeThemeStyleJSON, 'name'>) {+ if (options) {+ this.fromJson({ ...options, name });+ }++ this._name = name;+ }++ /**+ * Gets the name of the range theme style.The name is read only, and use to identifier the range theme style.+ * @returns {string} The name of the range theme style.+ */+ getName(): string {+ return this._name;+ }++ getWholeStyle(): Nullable<IRangeThemeStyleItem> {+ return this.wholeStyle;+ }++ setWholeStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.wholeStyle = style;+ }++ getFirstRowStyle(): Nullable<IRangeThemeStyleItem> {+ return this.firstRowStyle;+ }++ setFirstRowStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.firstRowStyle = style;+ }++ getSecondRowStyle(): Nullable<IRangeThemeStyleItem> {+ return this.secondRowStyle;+ }++ setSecondRowStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.secondRowStyle = style;+ }++ getLastRowStyle(): Nullable<IRangeThemeStyleItem> {+ return this.lastRowStyle;+ }++ setLastRowStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.lastRowStyle = style;+ }++ getFirstColumnStyle(): Nullable<IRangeThemeStyleItem> {+ return this.firstColumnStyle;+ }++ setFirstColumnStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.firstColumnStyle = style;+ }++ getSecondColumnStyle(): Nullable<IRangeThemeStyleItem> {+ return this.secondColumnStyle;+ }++ setSecondColumnStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.secondColumnStyle = style;+ }++ getLastColumnStyle(): Nullable<IRangeThemeStyleItem> {+ return this.lastColumnStyle;+ }++ setLastColumnStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.lastColumnStyle = style;+ }++ getHeaderRowStyle(): Nullable<IRangeThemeStyleItem> {+ return this.headerRowStyle;+ }++ setHeaderRowStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.headerRowStyle = style;+ }++ getHeaderColumnStyle(): Nullable<IRangeThemeStyleItem> {+ return this.headerColumnStyle;+ }++ setHeaderColumnStyle(style: Nullable<IRangeThemeStyleItem>): void {+ this.headerColumnStyle = style;+ }++ public getStyle(offsetRow: number, offsetCol: number, isLastRow: boolean, isLastCol: boolean) {+ let mergeNumber = 0;++ if (isLastRow) {+ mergeNumber = mergeNumber | STYLE_MAP.lastRowStyle;+ }++ if (isLastCol) {+ mergeNumber = mergeNumber | STYLE_MAP.lastColumnStyle;+ }++ if (offsetRow >= 0 && offsetCol >= 0) {+ mergeNumber = mergeNumber | STYLE_MAP.wholeStyle;+ }++ if (offsetRow % 2 === 1) {+ mergeNumber = mergeNumber | STYLE_MAP.firstRowStyle;+ }++ if (offsetRow % 2 === 0) {+ mergeNumber = mergeNumber | STYLE_MAP.secondRowStyle;+ }++ if (offsetRow === 0) {+ mergeNumber = mergeNumber | STYLE_MAP.headerRowStyle;+ }++ if (offsetCol === 0) {+ mergeNumber = mergeNumber | STYLE_MAP.headerColumnStyle;+ }++ if (offsetCol % 2 === 1) {+ mergeNumber = mergeNumber | STYLE_MAP.firstColumnStyle;+ }++ if (offsetCol % 2 === 0) {+ mergeNumber = mergeNumber | STYLE_MAP.secondColumnStyle;+ }++ // it means no style should be merged+ if (mergeNumber === 0) {+ return null;+ }+ return this._getMergeStyle(mergeNumber);+ }++ private _getMergeStyle(mergeNumber: number) {+ let style = this._mergeCacheMap.get(mergeNumber);+ if (!style) {+ style = this._mergeStyle(mergeNumber);+ this._mergeCacheMap.set(mergeNumber, style);+ }+ return style;+ }++ private _mergeStyle(mergeNumber: number): IRangeThemeStyleItem {+ const rs: IRangeThemeStyleItem[] = [];+ // the push order means the priority of the style+ if (this.wholeStyle && (mergeNumber & STYLE_MAP.wholeStyle)) {+ rs.push(this.wholeStyle);+ }++ // zebra crossing+ if (this.firstColumnStyle && (mergeNumber & STYLE_MAP.firstColumnStyle)) {+ rs.push(this.firstColumnStyle);+ }+ if (this.secondColumnStyle && (mergeNumber & STYLE_MAP.secondColumnStyle)) {+ rs.push(this.secondColumnStyle);+ }++ if (this.firstRowStyle && (mergeNumber & STYLE_MAP.firstRowStyle)) {+ rs.push(this.firstRowStyle);+ }+ if (this.secondRowStyle && (mergeNumber & STYLE_MAP.secondRowStyle)) {+ rs.push(this.secondRowStyle);+ }++ // column header+ if (this.headerColumnStyle && (mergeNumber & STYLE_MAP.headerColumnStyle)) {+ rs.push(this.headerColumnStyle);+ }+ // last column+ if (this.lastColumnStyle && (mergeNumber & STYLE_MAP.lastColumnStyle)) {+ rs.push(this.lastColumnStyle);+ }++ // row header+ if (this.headerRowStyle && (mergeNumber & STYLE_MAP.headerRowStyle)) {+ rs.push(this.headerRowStyle);+ }+ // last row+ if (this.lastRowStyle && (mergeNumber & STYLE_MAP.lastRowStyle)) {+ rs.push(this.lastRowStyle);+ }++ return composeStyles(rs as IStyleData[]);+ }++ toJson(): IRangeThemeStyleJSON {+ const jsonData: IRangeThemeStyleJSON = {+ name: this._name,+ };++ if (this.wholeStyle) {+ jsonData.wholeStyle = serializeRangeStyle(this.wholeStyle)!;+ }++ if (this.headerRowStyle) {+ jsonData.headerRowStyle = serializeRangeStyle(this.headerRowStyle)!;+ }++ if (this.headerColumnStyle) {+ jsonData.headerColumnStyle = serializeRangeStyle(this.headerColumnStyle)!;+ }++ if (this.firstRowStyle) {+ jsonData.firstRowStyle = serializeRangeStyle(this.firstRowStyle)!;+ }++ if (this.secondRowStyle) {+ jsonData.secondRowStyle = serializeRangeStyle(this.secondRowStyle)!;+ }++ if (this.lastRowStyle) {+ jsonData.lastRowStyle = serializeRangeStyle(this.lastRowStyle)!;+ }++ if (this.firstColumnStyle) {+ jsonData.firstColumnStyle = serializeRangeStyle(this.firstColumnStyle)!;+ }++ if (this.secondColumnStyle) {+ jsonData.secondColumnStyle = serializeRangeStyle(this.secondColumnStyle)!;+ }++ if (this.lastColumnStyle) {+ jsonData.lastColumnStyle = serializeRangeStyle(this.lastColumnStyle)!;+ }+ return jsonData;+ }++ fromJson(json: IRangeThemeStyleJSON): void {+ this._name = json.name;+ if (json.wholeStyle) {+ this.wholeStyle = serializeRangeStyle(json.wholeStyle);+ }++ if (json.headerRowStyle) {+ this.headerRowStyle = serializeRangeStyle(json.headerRowStyle);+ }++ if (json.headerColumnStyle) {+ this.headerColumnStyle = serializeRangeStyle(json.headerColumnStyle);+ }++ if (json.firstRowStyle) {+ this.firstRowStyle = serializeRangeStyle(json.firstRowStyle);+ }++ if (json.secondRowStyle) {+ this.secondRowStyle = serializeRangeStyle(json.secondRowStyle);+ }++ if (json.lastRowStyle) {+ this.lastRowStyle = serializeRangeStyle(json.lastRowStyle);+ }++ if (json.firstColumnStyle) {+ this.firstColumnStyle = serializeRangeStyle(json.firstColumnStyle);+ }++ if (json.secondColumnStyle) {+ this.secondColumnStyle = serializeRangeStyle(json.secondColumnStyle);+ }++ if (json.lastColumnStyle) {+ this.lastColumnStyle = serializeRangeStyle(json.lastColumnStyle);+ }+ }++ dispose(): void {+ this._mergeCacheMap.clear();+ }+}+diff --git a/packages/sheets/src/model/range-themes/build-in-theme.factory.ts b/packages/sheets/src/model/range-themes/build-in-theme.factory.tsnew file mode 100644index 0000000000..64c6835cda--- /dev/null+++ b/packages/sheets/src/model/range-themes/build-in-theme.factory.ts@@ -0,0 +1,290 @@+/**+ * 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, HorizontalAlign } from '@univerjs/core';+import { RangeThemeStyle } from '../range-theme-util';++export const lightRangeThemeBuilder = (baseName: string, header: string, color: string) => {+ return new RangeThemeStyle(`light-${baseName}`, {+ headerRowStyle: {+ bg: {+ rgb: header,+ },+ },+ firstColumnStyle: {+ bg: {+ rgb: 'rgb(255, 255, 255)',+ },+ },+ secondColumnStyle: {+ bg: {+ rgb: color,+ },+ },+ lastRowStyle: {+ bg: {+ rgb: header,+ },+ },+ });+};+export const middleRangeThemeBuilder = (baseName: string, rowHeader: string, colHeader: string) => {+ return new RangeThemeStyle(`middle-${baseName}`, {+ headerRowStyle: {+ bg: {+ rgb: rowHeader,+ },+ },+ headerColumnStyle: {+ bg: {+ rgb: colHeader,+ },+ },+ secondRowStyle: {+ bg: {+ rgb: colHeader,+ },+ },+ lastRowStyle: {+ bg: {+ rgb: rowHeader,+ },+ },+ lastColumnStyle: {+ bg: {+ rgb: colHeader,+ },+ },+ });+};++export const darkRangeThemeBuilder = (baseName: string, rowHeader: string, firstRow: string, secondRow: string) => {+ return new RangeThemeStyle(`dark-${baseName}`, {+ headerRowStyle: {+ bg: {+ rgb: rowHeader,+ },+ cl: {+ rgb: 'rgb(255, 255, 255)',+ },+ ht: HorizontalAlign.CENTER,+ bl: BooleanNumber.TRUE,+ },+ firstRowStyle: {+ bg: {+ rgb: firstRow,+ },+ },+ secondRowStyle: {+ bg: {+ rgb: secondRow,+ },+ },+ lastRowStyle: {+ bg: {+ rgb: rowHeader,+ },+ },+ });+};++const lightConfig = [+ {+ baseName: 'blue',+ header: 'rgb(164, 202, 254)',+ color: 'rgb(225, 239, 254)',+ },+ {+ baseName: 'grey',+ header: 'rgb(205, 208, 216)',+ color: 'rgb(238, 239, 241)',+ },+ {+ baseName: 'red',+ header: 'rgb(248, 180, 180)',+ color: 'rgb(253, 232, 232)',+ },+ {+ baseName: 'orange',+ header: 'rgb(253, 186, 140)',+ color: 'rgb(254, 236, 220)',+ },+ {+ baseName: 'yellow',+ header: 'rgb(250, 200, 21)',+ color: 'rgb(255, 244, 185)',+ },+ {+ baseName: 'green',+ header: 'rgb(132, 225, 188)',+ color: 'rgb(222, 247, 236)',+ },++ {+ baseName: 'azure',+ header: 'rgb(126, 220, 226)',+ color: 'rgb(213, 245, 246)',+ },+ {+ baseName: 'indigo',+ header: 'rgb(186, 198, 248)',+ color: 'rgb(233, 237, 255)',+ },+ {+ baseName: 'purple',+ header: 'rgb(202, 191, 253)',+ color: 'rgb(237, 235, 254)',+ },+ {+ baseName: 'magenta',+ header: 'rgb(248, 180, 217)',+ color: 'rgb(252, 232, 243)',+ },+];++const middleConfig = [+ {+ baseName: 'blue',+ rowHeader: 'rgb(63, 131, 248)',+ colHeader: 'rgb(195, 221, 253)',+ },+ {+ baseName: 'grey',+ rowHeader: 'rgb(95, 101, 116)',+ colHeader: 'rgb(227, 229, 234)',+ },+ {+ baseName: 'red',+ rowHeader: 'rgb(240, 82, 82)',+ colHeader: 'rgb(251, 213, 213)',+ },+ {+ baseName: 'orange',+ rowHeader: 'rgb(255, 90, 31)',+ colHeader: 'rgb(252, 217, 189)',+ },+ {+ baseName: 'yellow',+ rowHeader: 'rgb(212, 157, 15)',+ colHeader: 'rgb(252, 220, 106)',+ },+ {+ baseName: 'green',+ rowHeader: 'rgb(13, 164, 113)',+ colHeader: 'rgb(188, 240, 218)',+ },+ {+ baseName: 'azure',+ rowHeader: 'rgb(6, 148, 162)',+ colHeader: 'rgb(175, 236, 239)',+ },+ {+ baseName: 'indigo',+ rowHeader: 'rgb(70, 106, 247)',+ colHeader: 'rgb(210, 218, 250)',+ },+ {+ baseName: 'purple',+ rowHeader: 'rgb(144, 97, 249)',+ colHeader: 'rgb(220, 215, 254)',+ },+ {+ baseName: 'magenta',+ rowHeader: 'rgb(231, 70, 148)',+ colHeader: 'rgb(250, 209, 232)',+ },+];++const darkConfig = [+ {+ baseName: 'blue',+ rowHeader: 'rgb(30, 66, 159)',+ firstRow: 'rgb(195, 221, 253)',+ secondRow: 'rgb(118, 169, 250)',+ },+ {+ baseName: 'grey',+ rowHeader: 'rgb(44, 48, 64)',+ firstRow: 'rgb(227, 229, 234)',+ secondRow: 'rgb(151, 157, 172)',+ },+ {+ baseName: 'red',+ rowHeader: 'rgb(155, 28, 28)',+ firstRow: 'rgb(251, 213, 213)',+ secondRow: 'rgb(249, 128, 128)',+ },+ {+ baseName: 'orange',+ rowHeader: 'rgb(180, 52, 3)',+ firstRow: 'rgb(252, 217, 189)',+ secondRow: 'rgb(255, 138, 76)',+ },+ {+ baseName: 'yellow',+ rowHeader: 'rgb(154, 109, 21)',+ firstRow: 'rgb(252, 220, 106)',+ secondRow: 'rgb(212, 157, 15)',+ },+ {+ baseName: 'green',+ rowHeader: 'rgb(4, 108, 78)',+ firstRow: 'rgb(188, 240, 218)',+ secondRow: 'rgb(49, 196, 141)',+ },+ {+ baseName: 'azure',+ rowHeader: 'rgb(3, 102, 114)',+ firstRow: 'rgb(175, 236, 239)',+ secondRow: 'rgb(22, 189, 202)',+ },+ {+ baseName: 'indigo',+ rowHeader: 'rgb(16, 51, 191)',+ firstRow: 'rgb(210, 218, 250)',+ secondRow: 'rgb(98, 128, 249)',+ },+ {+ baseName: 'purple',+ rowHeader: 'rgb(74, 29, 150)',+ firstRow: 'rgb(220, 215, 254)',+ secondRow: 'rgb(172, 148, 250)',+ },+ {+ baseName: 'magenta',+ rowHeader: 'rgb(153, 21, 75)',+ firstRow: 'rgb(250, 209, 232)',+ secondRow: 'rgb(241, 126, 184)',+ },+];++const lightThemes = lightConfig.map(({ baseName, header, color }) => {+ return lightRangeThemeBuilder(baseName, header, color);+});++const middleThemes = middleConfig.map(({ baseName, rowHeader, colHeader }) => {+ return middleRangeThemeBuilder(baseName, rowHeader, colHeader);+});++const darkThemes = darkConfig.map(({ baseName, rowHeader, firstRow, secondRow }) => {+ return darkRangeThemeBuilder(baseName, rowHeader, firstRow, secondRow);+});++export const buildInThemes = [+ ...lightThemes,+ ...middleThemes,+ ...darkThemes,+];diff --git a/packages/sheets/src/model/range-themes/default.ts b/packages/sheets/src/model/range-themes/default.tsnew file mode 100644index 0000000000..6b113abcd3--- /dev/null+++ b/packages/sheets/src/model/range-themes/default.ts@@ -0,0 +1,52 @@+/**+ * 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 { IRangeThemeStyleJSON } from '../range-theme-util';+import { BooleanNumber, BorderStyleTypes, HorizontalAlign } from '@univerjs/core';+import { RangeThemeStyle } from '../range-theme-util';++const defaultRangeThemeStyleJSON: Omit<IRangeThemeStyleJSON, 'name'> = {++ headerRowStyle: {+ bg: {+ rgb: 'rgb(68,114,196)',+ },+ cl: {+ rgb: 'rgb(255,255,255)',+ },+ ht: HorizontalAlign.CENTER,+ bl: BooleanNumber.TRUE,+ },+ firstRowStyle: {+ bg: {+ rgb: 'rgb(217,225,242)',+ },+ },+ lastRowStyle: {+ bd: {+ t: {+ s: BorderStyleTypes.THIN,+ cl: {+ rgb: 'rgb(68,114,196)',+ },+ },+ },+ ht: HorizontalAlign.CENTER,+ bl: BooleanNumber.TRUE,+ },+};+export const defaultRangeThemeStyle = new RangeThemeStyle('default', defaultRangeThemeStyleJSON);+diff --git a/packages/sheets/src/services/range-theme-service.ts b/packages/sheets/src/services/range-theme-service.tsnew file mode 100644index 0000000000..e05be5cf47--- /dev/null+++ b/packages/sheets/src/services/range-theme-service.ts@@ -0,0 +1,70 @@+/**+ * 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 { IRangeThemeRangeInfo } from '../model/range-theme-model';+import type { RangeThemeStyle } from '../model/range-theme-util';+import { Disposable, Inject } from '@univerjs/core';+import { SheetRangeThemeModel } from '../model/range-theme-model';++export class SheetRangeThemeService extends Disposable {+ constructor(+ @Inject(SheetRangeThemeModel) private _sheetRangeThemeModel: SheetRangeThemeModel+ ) {+ super();+ }++ /**+ * Register a custom range theme style.+ * @param {string} unitId Which unit to register the range theme style.+ * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register.+ */+ registerRangeTheme(unitId: string, rangeThemeStyle: RangeThemeStyle): void {+ this._sheetRangeThemeModel.registerRangeThemeStyle(unitId, rangeThemeStyle);+ }++ /**+ * Get custom register themes name list+ * @returns {string[]} The list of custom register themes name.+ */+ getALLRegisterThemes(): string[] {+ return this._sheetRangeThemeModel.getALLRegisteredTheme();+ }++ /**+ * Register range theme style to the range.+ * @param {string} themeName The defined theme name.+ * @param {IRangeThemeRangeInfo} rangeInfo The range info to apply the theme style.+ */+ registerRangeThemeStyle(themeName: string, rangeInfo: IRangeThemeRangeInfo): void {+ this._sheetRangeThemeModel.registerRangeThemeRule(themeName, rangeInfo);+ }++ /**+ * Get applied range theme style name.+ * @param {IRangeThemeRangeInfo} rangeInfo The range info to get the applied theme style.+ * @returns {string | undefined} The applied theme style name or not exist.+ */+ getAppliedRangeThemeStyle(rangeInfo: IRangeThemeRangeInfo): string | undefined {+ return this._sheetRangeThemeModel.getRegisteredRangeThemeStyle(rangeInfo);+ }++ /**+ * Get registered build-in range theme style+ */+ getRegisteredRangeThemes() {+ return this._sheetRangeThemeModel.getRegisteredRangeThemes();+ }+}diff --git a/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts b/packages/sheets/src/services/sheet-interceptor/interceptor-const.tsindex c5403afdc9..96b025b1e2 100644--- a/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts+++ b/packages/sheets/src/services/sheet-interceptor/interceptor-const.ts@@ -32,3 +32,7 @@ export enum InterceptCellContentPriority {NUMFMT = 10,CELL_IMAGE = 11,}+// used for define the range theme interceptor, it will also use to ignore the range theme interceptor+export const RangeThemeInterceptorId = 'sheet.interceptor.range-theme-id';++export const IgnoreRangeThemeInterceptorKey = 'sheet.interceptor.ignore-range-theme';diff --git a/packages/sheets/src/sheets-plugin.ts b/packages/sheets/src/sheets-plugin.tsindex d7485a65c4..c403ccc88c 100644--- a/packages/sheets/src/sheets-plugin.ts+++ b/packages/sheets/src/sheets-plugin.ts@@ -28,8 +28,9 @@ import { NumberCellDisplayController } from './controllers/number-cell.controlleimport { RangeProtectionRenderModel } from './model/range-protection-render.model';import { RangeProtectionRuleModel } from './model/range-protection-rule.model';import { RangeProtectionCache } from './model/range-protection.cache';-import { BorderStyleManagerService } from './services/border-style-manager.service';+import { SheetRangeThemeModel } from './model/range-theme-model';+import { BorderStyleManagerService } from './services/border-style-manager.service';import { ExclusiveRangeService, IExclusiveRangeService } from './services/exclusive-range/exclusive-range-service';import { NumfmtService } from './services/numfmt/numfmt.service';import { INumfmtService } from './services/numfmt/type';@@ -37,6 +38,7 @@ import { RangeProtectionRefRangeService } from './services/permission/range-permimport { RangeProtectionService } from './services/permission/range-permission/range-protection.service';import { WorkbookPermissionService } from './services/permission/workbook-permission/workbook-permission.service';import { WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from './services/permission/worksheet-permission';+import { SheetRangeThemeService } from './services/range-theme-service';import { RefRangeService } from './services/ref-range/ref-range.service';import { SheetsSelectionsService } from './services/selections/selection.service';import { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';@@ -85,6 +87,7 @@ export class UniverSheetsPlugin extends Plugin {[WorkbookPermissionService],[INumfmtService, { useClass: NumfmtService }],[SheetInterceptorService],+ [SheetRangeThemeService],// controllers[BasicWorksheetController],@@ -97,6 +100,9 @@ export class UniverSheetsPlugin extends Plugin {[WorksheetProtectionRuleModel],[WorksheetProtectionPointModel],+ // range theme+ [SheetRangeThemeModel],+// range protection[RangeProtectionRenderModel],[RangeProtectionRuleModel],@@ -141,6 +147,7 @@ export class UniverSheetsPlugin extends Plugin {touchDependencies(this._injector, [[CalculateResultApplyController],[DefinedNameDataController],+ [SheetRangeThemeModel],[NumberCellDisplayController],[RangeProtectionRenderModel],[RangeProtectionRefRangeService],diff --git a/tests/formula-integration/src/__snapshots__/test-formula-correctness---basic-sum-result.json b/tests/formula-integration/src/__snapshots__/test-formula-correctness---basic-sum-result.jsonindex 1439339abd..db978fa690 100644--- a/tests/formula-integration/src/__snapshots__/test-formula-correctness---basic-sum-result.json+++ b/tests/formula-integration/src/__snapshots__/test-formula-correctness---basic-sum-result.json@@ -107,6 +107,10 @@"name": "SHEET_DEFINED_NAME_PLUGIN","data": "{}"},+ {+ "name": "SHEET_RANGE_THEME_MODEL_PLUGIN",+ "data": "{}"+ },{"name": "SHEET_DATA_VALIDATION_PLUGIN","data": "{}"