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: supplement sheets-numfmt text format alert and mark config (#4852)
wpxp12345664034c78cece
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex 016d556bf6..45fb02386c 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -116,7 +116,10 @@ function createNewInstance() {univer.registerPlugin(UniverSheetsPlugin, { notExecuteFormula: true });univer.registerPlugin(UniverSheetsUIPlugin);- univer.registerPlugin(UniverSheetsNumfmtPlugin);+ univer.registerPlugin(UniverSheetsNumfmtPlugin, {+ disableTextFormatAlert: true,+ disableTextFormatMark: true,+ });univer.registerPlugin(UniverSheetsZenEditorPlugin);univer.registerPlugin(UniverFormulaEnginePlugin, { notExecuteFormula: true });univer.registerPlugin(UniverSheetsNumfmtUIPlugin);diff --git a/packages/sheets-numfmt-ui/src/controllers/config.schema.ts b/packages/sheets-numfmt-ui/src/controllers/config.schema.tsindex 88fde7f990..8a969c957a 100644--- a/packages/sheets-numfmt-ui/src/controllers/config.schema.ts+++ b/packages/sheets-numfmt-ui/src/controllers/config.schema.ts@@ -16,7 +16,7 @@import type { MenuConfig } from '@univerjs/ui';-export const SHEETS_NUMFMT_UI_PLUGIN_CONFIG_KEY = 'sheets-numfmt.config';+export const SHEETS_NUMFMT_UI_PLUGIN_CONFIG_KEY = 'sheets-numfmt-ui.config';export const configSymbol = Symbol(SHEETS_NUMFMT_UI_PLUGIN_CONFIG_KEY);diff --git a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.tsindex fc0eaca4f3..be28325e56 100644--- a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts+++ b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts@@ -16,10 +16,12 @@import type { Workbook } from '@univerjs/core';import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';-import { Disposable, Inject, isRealNum, LocaleService } from '@univerjs/core';+import type { IUniverSheetsNumfmtConfig } from '@univerjs/sheets-numfmt';+import { Disposable, IConfigService, Inject, isRealNum, LocaleService } from '@univerjs/core';import { FormulaDataModel } from '@univerjs/engine-formula';import { isTextFormat } from '@univerjs/engine-numfmt';import { INumfmtService } from '@univerjs/sheets';+import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY } from '@univerjs/sheets-numfmt';import { CellAlertManagerService, CellAlertType, HoverManagerService } from '@univerjs/sheets-ui';import { IZenZoneService } from '@univerjs/ui';import { debounceTime } from 'rxjs';@@ -34,7 +36,8 @@ export class NumfmtAlertRenderController extends Disposable implements IRenderMo@Inject(LocaleService) private readonly _localeService: LocaleService,@Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel,@IZenZoneService private readonly _zenZoneService: IZenZoneService,- @Inject(INumfmtService) private _numfmtService: INumfmtService+ @Inject(INumfmtService) private _numfmtService: INumfmtService,+ @IConfigService private readonly _configService: IConfigService) {super();this._init();@@ -77,6 +80,11 @@ export class NumfmtAlertRenderController extends Disposable implements IRenderMo// Preventing blank objectif (isTextFormat(numfmtValue.pattern) && cellData?.v && isRealNum(cellData.v)) {+ // If the user has disabled the text format alert, do not show it+ if (this._configService.getConfig<IUniverSheetsNumfmtConfig>(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY)?.disableTextFormatAlert) {+ return;+ }+const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);const currentLoc = currentAlert?.alert?.location;if (@@ -90,7 +98,7 @@ export class NumfmtAlertRenderController extends Disposable implements IRenderMo}this._cellAlertManagerService.showAlert({- type: CellAlertType.ERROR,+ type: CellAlertType.WARNING,title: this._localeService.t('info.error'),message: this._localeService.t('info.forceStringInfo'),location,diff --git a/packages/sheets-numfmt/src/controllers/config.schema.ts b/packages/sheets-numfmt/src/controllers/config.schema.tsnew file mode 100644index 0000000000..057d545f7f--- /dev/null+++ b/packages/sheets-numfmt/src/controllers/config.schema.ts@@ -0,0 +1,32 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++export const SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = 'sheets-numfmt.config';++export const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);++export interface IUniverSheetsNumfmtConfig {+ /**+ * Whether to disable the text format alert.+ */+ disableTextFormatAlert?: boolean;+ /**+ * Whether to disable the text format mark.+ */+ disableTextFormatMark?: boolean;+}++export const defaultPluginConfig: IUniverSheetsNumfmtConfig = {};diff --git a/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.tsindex 12ed9f6dc3..37190df0f6 100644--- a/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts+++ b/packages/sheets-numfmt/src/controllers/numfmt-cell-content.controller.ts@@ -21,10 +21,12 @@ import type {Workbook,} from '@univerjs/core';import type { ISetNumfmtMutationParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';+import type { IUniverSheetsNumfmtConfig } from './config.schema';import {CellValueType,Disposable,ICommandService,+ IConfigService,Inject,InterceptorEffectEnum,IUniverInstanceService,@@ -39,6 +41,7 @@ import { isTextFormat } from '@univerjs/engine-numfmt';import { checkCellValueType, InterceptCellContentPriority, INTERCEPTOR_POINT, INumfmtService, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService } from '@univerjs/sheets';import { BehaviorSubject, merge, of, skip, switchMap } from 'rxjs';import { getPatternPreviewIgnoreGeneral } from '../utils/pattern';+import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY } from './config.schema';const TEXT_FORMAT_MARK = {tl: {@@ -55,8 +58,8 @@ export class SheetsNumfmtCellContentController extends Disposable {@Inject(ThemeService) private _themeService: ThemeService,@Inject(ICommandService) private _commandService: ICommandService,@Inject(INumfmtService) private _numfmtService: INumfmtService,- @Inject(LocaleService) private _localeService: LocaleService-+ @Inject(LocaleService) private _localeService: LocaleService,+ @IConfigService private readonly _configService: IConfigService) {super();this._initInterceptorCellContent();@@ -133,8 +136,16 @@ export class SheetsNumfmtCellContentController extends Disposable {return next(cell);}- // Add error marker to text format number+ // Add error marker to text format numberif (isTextFormat(numfmtValue.pattern)) {+ // If the user has disabled the text format mark, do not show it+ if (this._configService.getConfig<IUniverSheetsNumfmtConfig>(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY)?.disableTextFormatMark) {+ return next({+ ...cell,+ t: CellValueType.STRING,+ });+ }+return next({...cell,t: CellValueType.STRING,diff --git a/packages/sheets-numfmt/src/index.ts b/packages/sheets-numfmt/src/index.tsindex c5aae7cdd4..ce05dea421 100644--- a/packages/sheets-numfmt/src/index.ts+++ b/packages/sheets-numfmt/src/index.ts@@ -24,6 +24,7 @@ export { getCurrencyType } from './utils/currency';export { currencySymbols } from './base/const/currency-symbols';export { SheetsNumfmtCellContentController } from './controllers/numfmt-cell-content.controller';export { getCurrencyFormatOptions, getCurrencyOptions, getDateFormatOptions, getNumberFormatOptions } from './utils/options';+export { type IUniverSheetsNumfmtConfig, SHEETS_NUMFMT_PLUGIN_CONFIG_KEY } from './controllers/config.schema';// #region - all commandsdiff --git a/packages/sheets-numfmt/src/numfmt-plugin.ts b/packages/sheets-numfmt/src/numfmt-plugin.tsindex 5d2a46a4ec..bb198eba6c 100644--- a/packages/sheets-numfmt/src/numfmt-plugin.ts+++ b/packages/sheets-numfmt/src/numfmt-plugin.ts@@ -14,7 +14,8 @@* limitations under the License.*/-import { DependentOn, ICommandService, Inject, Injector, Plugin, registerDependencies, touchDependencies, UniverInstanceType } from '@univerjs/core';+import type { IUniverSheetsNumfmtConfig } from './controllers/config.schema';+import { DependentOn, ICommandService, IConfigService, Inject, Injector, merge, Plugin, registerDependencies, touchDependencies, UniverInstanceType } from '@univerjs/core';import { UniverSheetsPlugin } from '@univerjs/sheets';import { SHEET_NUMFMT_PLUGIN } from './base/const/plugin-name';import { AddDecimalCommand } from './commands/commands/add-decimal.command';@@ -22,6 +23,7 @@ import { SetCurrencyCommand } from './commands/commands/set-currency.command';import { SetNumfmtCommand } from './commands/commands/set-numfmt.command';import { SetPercentCommand } from './commands/commands/set-percent.command';import { SubtractDecimalCommand } from './commands/commands/subtract-decimal.command';+import { defaultPluginConfig, SHEETS_NUMFMT_PLUGIN_CONFIG_KEY } from './controllers/config.schema';import { SheetsNumfmtCellContentController } from './controllers/numfmt-cell-content.controller';import { NumfmtCurrencyController } from './controllers/numfmt-currency.controller';import { MenuCurrencyService } from './service/menu.currency.service';@@ -32,11 +34,21 @@ export class UniverSheetsNumfmtPlugin extends Plugin {static override type = UniverInstanceType.UNIVER_SHEET;constructor(- private readonly _config: undefined = undefined,+ private readonly _config: Partial<IUniverSheetsNumfmtConfig> = defaultPluginConfig,@Inject(Injector) override readonly _injector: Injector,+ @IConfigService private readonly _configService: IConfigService,@ICommandService private readonly _commandService: ICommandService) {super();++ // Manage the plugin configuration.+ const { ...rest } = merge(+ {},+ defaultPluginConfig,+ this._config+ );++ this._configService.setConfig(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY, rest);}override onStarting(): void {