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(code): sheets-plugin-numfmt code fix
jerryedc94f6f82fe
diff --git a/packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.tsx b/packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.tsxindex 8ca365f232..28ad5bb1f3 100644--- a/packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.tsx+++ b/packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.tsx@@ -1,6 +1,4 @@-import { Component, VNode } from '@univerjs/base-ui';-import { PLUGIN_NAMES } from '@univerjs/core';-import { SheetPlugin } from '@univerjs/base-sheets';+import { ColorPickerCircleButton, Component, SiderModal, VNode } from '@univerjs/base-ui';import { BorderType } from '../../Enum/BorderType';import { NormalType } from '../../Enum/NormalType';import { OVER_GRID_IMAGE_PLUGIN_NAME } from '../../Const/PLUGIN_NAME';@@ -35,10 +33,8 @@ export class ImagePanelUI extends Component<ImagePanelUIProps> {}render(): VNode {- const ColorPickerCircleButton = this.getComponentRender().renderFunction('ColorPickerCircleButton');- const SiderModal = this.getComponentRender().renderFunction('SiderModal');return (- <SiderModal pluginName={OVER_GRID_IMAGE_PLUGIN_NAME} title={'图片设置'} style={{}}>+ <SiderModal name={OVER_GRID_IMAGE_PLUGIN_NAME} title={'图片设置'} style={{}}><div className={Style.imagePanelSetting}>{/* 常规 */}<div className={Style.section}>@@ -119,8 +115,8 @@ export class ImagePanelUI extends Component<ImagePanelUIProps> {}closed() {- const plugin: SheetPlugin = this.getPluginByName(PLUGIN_NAMES.SPREADSHEET)!;- plugin.showSiderByName(OVER_GRID_IMAGE_PLUGIN_NAME, false);+ // const plugin: SheetPlugin = this.getPluginByName(PLUGIN_NAMES.SPREADSHEET)!;+ // plugin.showSiderByName(OVER_GRID_IMAGE_PLUGIN_NAME, false);}componentWillMount() {diff --git a/packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.tsx b/packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.tsxindex da310e7c83..a093145f8e 100644--- a/packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.tsx+++ b/packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.tsx@@ -1,6 +1,4 @@-import { Component, IToolbarItemProps, VNode } from '@univerjs/base-ui';-import { SheetContext } from '@univerjs/core';-import { FileSelected } from '../../Library/FileSelected';+import { Component } from '@univerjs/base-ui';export interface ImageUploadButtonUIProps {chooseCallback: (url: string, file: File) => void;@@ -11,19 +9,18 @@ export class ImageUploadButtonUI extends Component<ImageUploadButtonUIProps> {this.state = {};}- render(): VNode {- const SingleButton = this.getComponentRender().renderFunction('SingleButton');- const OrderIcon = this.getComponentRender().renderFunction('OrderIcon');- const Props: IToolbarItemProps = {- locale: 'ImageUploadButtonUI',- type: 'single',- label: <OrderIcon />,- show: true,- onClick: async (item: IToolbarItemProps, context: SheetContext) => {- const file = await FileSelected.chooseImage();- this.props.chooseCallback(URL.createObjectURL(file), file);- },- };- return <SingleButton tooltip={Props.tooltip} key={Props.locale} name={Props.locale} label={Props.label} onClick={Props.onClick} />;+ render() {+ // const Props: IToolbarItemProps = {+ // locale: 'ImageUploadButtonUI',+ // type: 'single',+ // label: <OrderIcon />,+ // show: true,+ // onClick: async (item: IToolbarItemProps, context: SheetContext) => {+ // const file = await FileSelected.chooseImage();+ // this.props.chooseCallback(URL.createObjectURL(file), file);+ // },+ // };+ // return <SingleButton tooltip={Props.tooltip} key={Props.locale} name={Props.locale} label={Props.label} onClick={Props.onClick} />;+ return undefined;}}diff --git a/packages/sheets-plugin-numfmt/package.json b/packages/sheets-plugin-numfmt/package.jsonindex 4539a6eeac..38a3a0f8bd 100644--- a/packages/sheets-plugin-numfmt/package.json+++ b/packages/sheets-plugin-numfmt/package.json@@ -54,6 +54,7 @@"@univerjs/base-ui": "workspace:^0.0.1","@univerjs/common-plugin-data": "workspace:^0.0.1","@univerjs/core": "workspace:^0.0.1",+ "@univerjs/ui-plugin-sheets": "workspace:^0.0.1","preact": "^10.12.1"}}diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.tsindex 265cfcb9fd..02bf8f2fc0 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts@@ -1,17 +1,19 @@import {+ PLUGIN_NAMES,+ ObjectMatrixPrimitiveType,Command,- Range,- IRangeData,ObjectMatrix,- ObjectMatrixPrimitiveType,- PLUGIN_NAMES,+ IRangeData,+ Range,ACTION_NAMES as CORE_ACTION_NAME,+ ICellData,ActionOperation,ISetRangeDataActionData,} from '@univerjs/core';import { BaseComponentRender } from '@univerjs/base-ui';-import { IToolbarItemProps, SheetPlugin } from '@univerjs/base-sheets';+import { SheetPlugin } from '@univerjs/base-sheets';import { numfmt } from '@univerjs/base-numfmt-engine';+import { IToolbarItemProps, SHEET_UI_PLUGIN_NAME, SheetUIPlugin } from '@univerjs/ui-plugin-sheets';import { ACTION_NAMES } from '../Basics/Enum';import { DEFAULT_DATA, NUMFMT_PLUGIN_NAME, NumftmConfig } from '../Basics/Const';import { NumfmtModel } from '../Model/NumfmtModel';@@ -22,19 +24,21 @@ import styles from '../View/UI/index.module.less';export class NumfmtController {protected _sheetPlugin: SheetPlugin;- protected _model: NumfmtModel;-protected _numfmtList: IToolbarItemProps;+ protected _model: NumfmtModel;+protected _plugin: NumfmtPlugin;+ protected _sheetUIPlugin: SheetUIPlugin;+protected _render: BaseComponentRender;constructor(plugin: NumfmtPlugin) {+ this._sheetUIPlugin = plugin.getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);this._model = new NumfmtModel();this._plugin = plugin;this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;-const executeFormatter = (type: string): void => {const manager = this._sheetPlugin.getSelectionManager();const workbook = this._plugin.getContext().getWorkBook();@@ -46,7 +50,7 @@ export class NumfmtController {}// update cell dataactiveRange.getRangeList().forEach((range) => {- let matrix = new ObjectMatrix();+ let matrix = new ObjectMatrix<ICellData>();Range.foreach(range, (row, col) => {const cell = cellMatrix.getValue(row, col);if (cell) {@@ -54,10 +58,10 @@ export class NumfmtController {matrix.setValue(row, col, { v: cell.v, m: formatter(cell.v) });}});- const setRangeDataAction = {+ const setRangeDataAction: ISetRangeDataActionData = {sheetId: activeSheet.getSheetId(),- actionName: CORE_ACTION_NAME.SET_RANGE_DATA_ACTION,cellValue: matrix.getData(),+ actionName: CORE_ACTION_NAME.SET_RANGE_DATA_ACTION,};const newSetRangeDataAction = ActionOperation.make<ISetRangeDataActionData>(setRangeDataAction).removeExtension().getAction();const cmd = new Command({ WorkBookUnit: workbook }, newSetRangeDataAction);@@ -143,31 +147,31 @@ export class NumfmtController {this._numfmtList = {name: NUMFMT_PLUGIN_NAME,type: 0,- tooltipLocale: 'toolbar.moreFormats',+ label: 'toolbar.moreFormats',className: styles.customFormat,show: NumftmConfig.show,border: true,children: [...CHILDREN_DATA,{- locale: 'defaultFmt.CustomFormats.text',- customSuffix: { name: 'RightIcon' },+ label: 'defaultFmt.CustomFormats.text',+ suffix: { name: 'RightIcon' },className: styles.customFormatMore,children: [{- locale: 'format.moreCurrency',+ label: 'format.moreCurrency',onClick: () => {this._plugin.getNumfmtModalController().showModal('currency', true);},},{- locale: 'format.moreDateTime',+ label: 'format.moreDateTime',onClick: () => {this._plugin.getNumfmtModalController().showModal('date', true);},},{- locale: 'format.moreNumber',+ label: 'format.moreNumber',onClick: () => {this._plugin.getNumfmtModalController().showModal('number', true);},@@ -176,7 +180,7 @@ export class NumfmtController {},],};- this._sheetPlugin.addToolButton(this._numfmtList);+ this._sheetUIPlugin.addToolButton(this._numfmtList);}getNumfmtBySheetIdConfig(sheetId: string): ObjectMatrixPrimitiveType<string> {diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.tsindex 217d4fb023..9eb4bd068f 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts@@ -1,10 +1,11 @@import { ComponentChildren } from '@univerjs/base-ui';import { SheetPlugin } from '@univerjs/base-sheets';import { PLUGIN_NAMES } from '@univerjs/core';-import { NUMBERFORMAT, NUMFMT_PLUGIN_NAME, CURRENCYDETAIL, DATEFMTLISG } from '../Basics/Const';+import { SHEET_UI_PLUGIN_NAME, SheetUIPlugin } from '@univerjs/ui-plugin-sheets/src';import { NumfmtPlugin } from '../NumfmtPlugin';import { FormatContent } from '../View/UI/FormatContent';import { NumfmtModal } from '../View/UI/NumfmtModal';+import { NUMBERFORMAT, NUMFMT_PLUGIN_NAME, CURRENCYDETAIL, DATEFMTLISG } from '../Basics/Const';interface GroupProps {locale: string;@@ -28,16 +29,19 @@ export interface ModalDataProps {}export class NumfmtModalController {- private _plugin: NumfmtPlugin;+ protected _plugin: NumfmtPlugin;++ protected _sheetUIPlugin: SheetUIPlugin;- private _sheetPlugin: SheetPlugin;+ protected _sheetPlugin: SheetPlugin;- private _numfmtModal: NumfmtModal;+ protected _numfmtModal: NumfmtModal;- private _modalData: ModalDataProps[];+ protected _modalData: ModalDataProps[];constructor(plugin: NumfmtPlugin) {- const locale = plugin.getContext().getLocale();+ const locale = plugin.getGlobalContext().getLocale();+ this._sheetUIPlugin = plugin.getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);this._plugin = plugin;this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;this._modalData = [@@ -162,7 +166,7 @@ export class NumfmtModalController {}private _initRegisterComponent() {- this._sheetPlugin.registerComponent(NUMFMT_PLUGIN_NAME + FormatContent.name, FormatContent);- this._sheetPlugin.registerModal(NUMFMT_PLUGIN_NAME + NumfmtModal.name, NumfmtModal);+ this._sheetUIPlugin.getComponentManager().register(NUMFMT_PLUGIN_NAME + FormatContent.name, FormatContent);+ this._sheetUIPlugin.getComponentManager().register(NUMFMT_PLUGIN_NAME + NumfmtModal.name, NumfmtModal);}}diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.tsindex bb0be86018..f2fa8dd48a 100644--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts@@ -3,7 +3,6 @@ import { NumfmtPluginObserve, install } from './Basics/Observer';import { NUMFMT_PLUGIN_NAME } from './Basics/Const/PLUGIN_NAME';import { NumfmtController } from './Controller/NumfmtController';import { NumfmtModalController } from './Controller/NumfmtModalController';-import { en, zh } from './Locale';import { NumfmtActionExtensionFactory } from './Basics/Register/NumfmtActionExtension';export interface INumfmtPluginConfig {}@@ -26,11 +25,6 @@ export class NumfmtPlugin extends Plugin<NumfmtPluginObserve, SheetContext> {onMounted(context: SheetContext): void {install(this);- context.getLocale().load({- en,- zh,- });-this._numfmtActionExtensionFactory = new NumfmtActionExtensionFactory(this);this._numfmtModalController = new NumfmtModalController(this);this._controller = new NumfmtController(this);diff --git a/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx b/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsxindex b57b10fab4..133ecb1d7f 100644--- a/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx+++ b/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx@@ -16,8 +16,7 @@ export class FormatContent extends Component<IProps, IState> {private _ref = createRef();initialize(props: IProps) {- // super(props);- const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ const component = this.getContext().getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;this._render = component.getComponentRender();}diff --git a/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx b/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsxindex 4e418660ae..4fb9ad4deb 100644--- a/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx+++ b/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx@@ -14,9 +14,8 @@ interface IState {export class NumfmtModal extends Component<IProps, IState> {private _render: BaseComponentRender;- initialize(props: IProps) {- // super(props);- const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ initialize(props: IProps): void {+ const component = this.getContext().getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;this._render = component.getComponentRender();this.state = {@@ -24,25 +23,21 @@ export class NumfmtModal extends Component<IProps, IState> {};}- componentDidMount() {- const plugin = this._context.getPluginManager().getPluginByName<NumfmtPlugin>(NUMFMT_PLUGIN_NAME)!;+ componentDidMount(): void {+ const plugin = this.getContext().getPluginManager().getPluginByName<NumfmtPlugin>(NUMFMT_PLUGIN_NAME)!;plugin.getObserver('onNumfmtModalDidMountObservable')!.notifyObservers(this);}- setModal(modalData: ModalDataProps[]) {- const SheetPlugin = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;-- modalData.forEach((item) => {- const Label = SheetPlugin.getRegisterComponent(item.children.name);+ setModal(modalData: ModalDataProps[]): void {+ const SheetPlugin: SheetPlugin = this.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;+ modalData.forEach((item): void => {+ const Label = this.context.componentManager.get(item.children.name);if (Label) {const props = item.children.props ?? {};item.modal = <Label {...props} />;}});-- this.setState({- modalData,- });+ this.setState({ modalData });}/**