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-ui): set bg active color in colorPicker & change deprecated method (#5827)
Roman Sergeev0d41cc207cfc
diff --git a/packages/core/src/sheets/util.ts b/packages/core/src/sheets/util.tsindex 819546be60..2eacab2565 100644--- a/packages/core/src/sheets/util.ts+++ b/packages/core/src/sheets/util.ts@@ -168,7 +168,7 @@ export function getFontFormat(format?: Nullable<IStyleData>): IStyleBase {if (!format) {return {};}- const { ff, fs, it, bl, ul, st, ol, cl } = format;+ const { ff, fs, it, bl, ul, st, ol, cl, bg } = format;const style: IStyleBase = {};ff && (style.ff = ff);fs && (style.fs = fs);@@ -178,6 +178,7 @@ export function getFontFormat(format?: Nullable<IStyleData>): IStyleBase {st && (style.st = st);ol && (style.ol = ol);cl && (style.cl = cl);+ bg && (style.bg = bg);return style;}diff --git a/packages/sheets-ui/src/controllers/menu/menu.ts b/packages/sheets-ui/src/controllers/menu/menu.tsindex 494aec0ed4..3511bd819d 100644--- a/packages/sheets-ui/src/controllers/menu/menu.ts+++ b/packages/sheets-ui/src/controllers/menu/menu.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IAccessor, Workbook } from '@univerjs/core';+import type { DocumentDataModel, IAccessor, Workbook } from '@univerjs/core';import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';import {BooleanNumber,@@ -609,7 +609,7 @@ export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuB};}-export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {+export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string, string | undefined> {const commandService = accessor.get(ICommandService);const themeService = accessor.get(ThemeService);@@ -625,6 +625,30 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMehoverable: false,selectable: false,},+ value$: new Observable<string>((subscriber) => {+ const defaultValue = DEFAULT_STYLES.bg.rgb;+ const calc = () => {+ const textRun = getFontStyleAtCursor(accessor);++ if (!textRun) {+ subscriber.next(defaultValue);+ return;+ }++ const color = textRun.ts?.bg?.rgb;++ subscriber.next(color ?? defaultValue);+ };++ const disposable = commandService.onCommandExecuted((c) => {+ if (c.id === SetRangeTextColorCommand.id) {+ calc();+ }+ });++ calc();+ return disposable.dispose;+ }),},],value$: new Observable<string>((subscriber) => {@@ -1400,7 +1424,7 @@ function getFontStyleAtCursor(accessor: IAccessor) {const univerInstanceService = accessor.get(IUniverInstanceService);const textSelectionService = accessor.get(DocSelectionManagerService);- const editorDataModel = univerInstanceService.getUniverDocInstance(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);+ const editorDataModel = univerInstanceService.getUnit<DocumentDataModel>(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);const activeTextRange = textSelectionService.getActiveTextRange();if (editorDataModel == null || activeTextRange == null) return null;