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
jerry9324e74cb009
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex bd924d5cb6..dd271a68a4 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -7,6 +7,7 @@ import { OperationPlugin } from '@univerjs/sheets-plugin-operation';import { ImportXlsxPlugin } from '@univerjs/sheets-plugin-import-xlsx';import { OverGridImagePlugin } from '@univerjs/sheets-plugin-image';import { FindPlugin } from '@univerjs/sheets-plugin-find';+import { NumfmtPlugin } from '@univerjs/sheets-plugin-numfmt';const uiDefaultConfigDemo = {container: 'universheet',@@ -71,3 +72,4 @@ FindPlugin.create().installTo(universheet);universheet.installPlugin(new OperationPlugin());universheet.installPlugin(new ImportXlsxPlugin());universheet.installPlugin(new OverGridImagePlugin());+universheet.installPlugin(new NumfmtPlugin());diff --git a/packages/base-ui/src/Framework/Preact.tsx b/packages/base-ui/src/Framework/Preact.tsxindex 847567ccab..f80b807a91 100644--- a/packages/base-ui/src/Framework/Preact.tsx+++ b/packages/base-ui/src/Framework/Preact.tsx@@ -1,4 +1,4 @@-import { Context } from '@univerjs/core/src/Basics/Context';+import { Context } from '@univerjs/core';import {cloneElement,Component as PreactComponent,@@ -45,12 +45,13 @@ abstract class Component<P = {}, S = {}> extends PreactComponent<P, S> {if (isValidElement(label)) {return label;}- const Label = this.context.componentManager.get((label as CustomComponent).name);- if (Label) {- const props = (label as CustomComponent).props ?? {};- return <Label {...props}></Label>;+ if (label) {+ const Label = this.context.componentManager.get((label as CustomComponent).name);+ if (Label) {+ const props = (label as CustomComponent).props ?? {};+ return <Label {...props}></Label>;+ }}-return null;}@@ -82,12 +83,13 @@ abstract class PureComponent<P = {}, S = {}> extends PreactPureComponent<P, S> {if (isValidElement(label)) {return label;}- const Label = this.context.componentManager.get((label as CustomComponent).name);- if (Label) {- const props = (label as CustomComponent).props ?? {};- return <Label {...props}></Label>;+ if (label) {+ const Label = this.context.componentManager.get((label as CustomComponent).name);+ if (Label) {+ const props = (label as CustomComponent).props ?? {};+ return <Label {...props}></Label>;+ }}-return null;}diff --git a/packages/core/test/Command/SetRangeDataAction.test.ts b/packages/core/test/Command/SetRangeDataAction.test.tsindex fc9f6c1a6a..f3a1ae9289 100644--- a/packages/core/test/Command/SetRangeDataAction.test.ts+++ b/packages/core/test/Command/SetRangeDataAction.test.ts@@ -1,65 +1,72 @@-/**- * @jest-environment jsdom- */-import { Workbook, Worksheet } from '../../src/Sheets/Domain';-import { SheetContext } from '../../src/Basics';-import {- SetRangeDataAction,- CommandManager,- ISetRangeDataActionData,-} from '../../src/Command';-import { ICellData, ObjectMatrixPrimitiveType } from '../../src';-import { IOCContainerStartUpReady } from '../ContainerStartUp';--jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));--test('Test SetRangeDataAction', () => {- const container = IOCContainerStartUpReady();- const context = container.getSingleton<SheetContext>('Context');- const workbook = container.getSingleton<Workbook>('WorkBook');-- const sheetId = 'sheet1';- const worksheet = new Worksheet(context, { id: sheetId });- workbook.insertSheet(worksheet);-- const observers = CommandManager.getActionObservers();- const actionName = 'SetRangeDataAction';-- // mock data- const cellValue: ObjectMatrixPrimitiveType<ICellData> = {- 0: {- 0: {- v: 1,- m: '1',- },- },- };-- const rangeData = {- startRow: 0,- endRow: 0,- startColumn: 0,- endColumn: 0,- };- const configure: ISetRangeDataActionData = {- actionName,- sheetId,- cellValue,- };-- const action = new SetRangeDataAction(configure, workbook, observers);-- const value = worksheet.getCellMatrix().getValue(0, 0);- expect(value && value.v).toEqual(1);-- action.undo();-- const preValue = worksheet.getCellMatrix().getValue(0, 0);-- expect(preValue && preValue.v).toEqual(undefined);-- action.redo();-- const nextValue = worksheet.getCellMatrix().getValue(0, 0);- expect(nextValue && nextValue.v).toEqual(1);-});+/**+ * @jest-environment jsdom+ */+import { Workbook, Worksheet } from '../../src/Sheets/Domain';+import { SheetContext } from '../../src/Basics';+import {+ CommandManager,+ ICellData,+ ISetRangeDataActionData,+ ObjectMatrixPrimitiveType,+ SetRangeDataAction,+} from '../../src';+import { IOCContainerStartUpReady } from '../ContainerStartUp';++jest.mock('nanoid', () => ({ nanoid: () => '12345678' }));++test('Test SetRangeDataAction', () => {+ const container = IOCContainerStartUpReady();+ const context = container.getSingleton<SheetContext>('Context');+ const workbook = container.getSingleton<Workbook>('WorkBook');++ const sheetId = 'sheet1';+ const worksheet = new Worksheet(context, { id: sheetId });+ workbook.insertSheet(worksheet);++ const observers = CommandManager.getActionObservers();+ const actionName = 'SetRangeDataAction';++ // mock data+ const cellValue: ObjectMatrixPrimitiveType<ICellData> = {+ 0: {+ 0: {+ v: 1,+ m: '1',+ },+ },+ };++ const rangeData = {+ startRow: 0,+ endRow: 0,+ startColumn: 0,+ endColumn: 0,+ };+ const configure: ISetRangeDataActionData = {+ actionName,+ sheetId,+ cellValue,+ };++ const action = new SetRangeDataAction(+ configure,+ {+ WorkBookUnit: workbook,+ },+ observers+ );++ const value = worksheet.getCellMatrix().getValue(0, 0);+ expect(value && value.v).toEqual(1);++ action.undo();++ const preValue = worksheet.getCellMatrix().getValue(0, 0);++ expect(preValue && preValue.v).toEqual(undefined);++ action.redo();++ const nextValue = worksheet.getCellMatrix().getValue(0, 0);+ expect(nextValue && nextValue.v).toEqual(1);+});diff --git a/packages/sheets-plugin-image/src/View/OverImageRender.ts b/packages/sheets-plugin-image/src/View/OverImageRender.tsindex e0e9f0815f..2297d95586 100644--- a/packages/sheets-plugin-image/src/View/OverImageRender.ts+++ b/packages/sheets-plugin-image/src/View/OverImageRender.ts@@ -1,19 +1,21 @@import { RenderEngine, EVENT_TYPE, Scene } from '@univerjs/base-render';import { PLUGIN_NAMES } from '@univerjs/core';+import { SHEET_UI_PLUGIN_NAME, SheetUIPlugin } from '@univerjs/ui-plugin-sheets';import { OverGridImagePlugin, OverGridImageProperty } from '../OverGridImagePlugin';import { OverImageShape } from './OverImageShape';export class OverImageRender {- static LAYER_Z_INDEX = 1000;-- private _plugin: OverGridImagePlugin;+ static LAYER_Z_INDEX: number = 1000;private _mainScene: Scene;+ private _plugin: OverGridImagePlugin;+private _activeShape: OverImageShape;constructor(plugin: OverGridImagePlugin) {- const engine = plugin.getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;+ const sheetPlugin = plugin.getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);+ const engine = sheetPlugin.getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;this._plugin = plugin;this._mainScene = engine.getScene('mainScene')!;plugin.getObserver('onAddImage')!.add((eventData: OverGridImageProperty) => {diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.tsindex 9eb4bd068f..8be2d7223a 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts@@ -1,7 +1,7 @@import { ComponentChildren } from '@univerjs/base-ui';import { SheetPlugin } from '@univerjs/base-sheets';import { PLUGIN_NAMES } from '@univerjs/core';-import { SHEET_UI_PLUGIN_NAME, SheetUIPlugin } from '@univerjs/ui-plugin-sheets/src';+import { SHEET_UI_PLUGIN_NAME, SheetUIPlugin } from '@univerjs/ui-plugin-sheets';import { NumfmtPlugin } from '../NumfmtPlugin';import { FormatContent } from '../View/UI/FormatContent';import { NumfmtModal } from '../View/UI/NumfmtModal';diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.tsindex f2fa8dd48a..d4650bd510 100644--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts@@ -18,7 +18,7 @@ export class NumfmtPlugin extends Plugin<NumfmtPluginObserve, SheetContext> {super(NUMFMT_PLUGIN_NAME);}- static create(config?: INumfmtPluginConfig) {+ static create(config?: INumfmtPluginConfig): NumfmtPlugin {return new NumfmtPlugin(config);}@@ -32,7 +32,7 @@ export class NumfmtPlugin extends Plugin<NumfmtPluginObserve, SheetContext> {actionRegister.add(this._numfmtActionExtensionFactory);}- onDestroy() {+ onDestroy(): void {super.onDestroy();const actionRegister = this.context.getCommandManager().getActionExtensionManager().getRegister();actionRegister.delete(this._numfmtActionExtensionFactory);@@ -50,7 +50,7 @@ export class NumfmtPlugin extends Plugin<NumfmtPluginObserve, SheetContext> {this._controller.setNumfmtByCoords(sheetId, row, column, format);}- getNumfmtModalController() {+ getNumfmtModalController(): NumfmtModalController {return this._numfmtModalController;}}diff --git a/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx b/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsxindex 133ecb1d7f..50a2169374 100644--- a/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx+++ b/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx@@ -56,20 +56,21 @@ export class FormatContent extends Component<IProps, IState> {* @returns {void}*/render() {- const { data } = this.props;-- return (- <div className={styles.formatContent} ref={this._ref}>- {this.getInput()}- <ul>- {data.map((item, index) => (- <li onClick={() => this.handleClick(item.value, index)}>- <span>{item.label}</span>- <span>{item.suffix}</span>- </li>- ))}- </ul>- </div>- );+ // const { data } = this.props;+ //+ // return (+ // <div className={styles.formatContent} ref={this._ref}>+ // {this.getInput()}+ // <ul>+ // {data.map((item, index) => (+ // <li onClick={() => this.handleClick(item.value, index)}>+ // <span>{item.label}</span>+ // <span>{item.suffix}</span>+ // </li>+ // ))}+ // </ul>+ // </div>+ // );+ return <></>;}}diff --git a/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx b/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsxindex 4fb9ad4deb..066cadb492 100644--- a/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx+++ b/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx@@ -46,20 +46,21 @@ export class NumfmtModal extends Component<IProps, IState> {* @returns {void}*/render() {- const Modal = this._render.renderFunction('Modal');- const { modalData } = this.state;- // Set Provider for entire Container- return (- <>- {modalData.map((item) => {- if (!item.show) return;- return (- <Modal title={item.title} visible={item.show} group={item.group} onCancel={item.onCancel}>- {item.modal}- </Modal>- );- })}- </>- );+ // const Modal = this._render.renderFunction('Modal');+ // const { modalData } = this.state;+ // // Set Provider for entire Container+ // return (+ // <>+ // {modalData.map((item) => {+ // if (!item.show) return;+ // return (+ // <Modal title={item.title} visible={item.show} group={item.group} onCancel={item.onCancel}>+ // {item.modal}+ // </Modal>+ // );+ // })}+ // </>+ // );+ return <></>;}}