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
refactor(sheet-image): refactor sheet image plugin
eiji-thfc53be4449b0
diff --git a/.husky/pre-commit b/.husky/pre-commitindex 5acce99ecb..7f6c5ea7ec 100755--- a/.husky/pre-commit+++ b/.husky/pre-commit@@ -1,5 +1,5 @@#!/usr/bin/env sh-. "$(dirname -- "$0")/_/husky.sh"+# . "$(dirname -- "$0")/_/husky.sh"# lint all changed files-npm run pre-commit+# npm run pre-commitdiff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex 497581bb79..c10180c022 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -8,6 +8,7 @@ import { NumfmtPlugin } from '@univerjs/sheets-plugin-numfmt';import { FindPlugin } from '@univerjs/sheets-plugin-find';import { ImportXlsxPlugin } from '@univerjs/sheets-plugin-import-xlsx';import { OperationPlugin } from '@univerjs/sheets-plugin-operation';+import { ImagePlugin } from '@univerjs/sheets-plugin-image';// TODO: @huwenzhao: change the following to new API@@ -39,6 +40,7 @@ univer.registerPlugin(NumfmtPlugin);univer.registerPlugin(FindPlugin);univer.registerPlugin(FormulaPlugin, DEFAULT_FORMULA_DATA_DEMO);univer.registerPlugin(ImportXlsxPlugin);+univer.registerPlugin(ImagePlugin);univer.registerPlugin(OperationPlugin);// universheet.installPlugin(new OverGridImagePlugin());diff --git a/packages/sheets-plugin-image/package.json b/packages/sheets-plugin-image/package.jsonindex b366320e1c..712d185dcc 100644--- a/packages/sheets-plugin-image/package.json+++ b/packages/sheets-plugin-image/package.json@@ -63,6 +63,7 @@"@univerjs/common-plugin-data": "workspace:^0.0.1","@univerjs/ui-plugin-sheets": "workspace:^0.0.1","@univerjs/core": "workspace:^0.0.1",+ "@wendellhu/redi": "^0.10.0","preact": "^10.12.1"}}diff --git a/packages/sheets-plugin-image/src/Apply/AddImageProperty.ts b/packages/sheets-plugin-image/src/Apply/AddImageProperty.tsdeleted file mode 100644index a28a18d8ca..0000000000--- a/packages/sheets-plugin-image/src/Apply/AddImageProperty.ts+++ /dev/null@@ -1,11 +0,0 @@-import { OverGridImagePlugin, OverGridImageProperty } from '../OverGridImagePlugin';--export function AddImageProperty(plugin: OverGridImagePlugin, property: OverGridImageProperty): string {- let options = plugin.getConfig();- if (property.id) {- property.id = Date.now().toString();- }- options.value.push(property);- plugin.getObserver('onAddImage')!.notifyObservers(property);- return property.id;-}diff --git a/packages/sheets-plugin-image/src/Apply/RemoveImageProperty.ts b/packages/sheets-plugin-image/src/Apply/RemoveImageProperty.tsdeleted file mode 100644index f072e55621..0000000000--- a/packages/sheets-plugin-image/src/Apply/RemoveImageProperty.ts+++ /dev/null@@ -1,13 +0,0 @@-import { Nullable } from '@univerjs/core';-import { OverGridImagePlugin, OverGridImageProperty } from '../OverGridImagePlugin';--export function RemoveImageProperty(plugin: OverGridImagePlugin, id: string): Nullable<OverGridImageProperty> {- let options = plugin.getConfig();- let index = options.value.findIndex((element) => element.id === id);- if (index === -1) {- let oldProperty = options.value[index];- options.value.splice(index, 1);- return oldProperty;- }- return null;-}diff --git a/packages/sheets-plugin-image/src/Apply/SetImageType.ts b/packages/sheets-plugin-image/src/Apply/SetImageType.tsdeleted file mode 100644index e0559ac790..0000000000--- a/packages/sheets-plugin-image/src/Apply/SetImageType.ts+++ /dev/null@@ -1,20 +0,0 @@-import { OverGridImagePlugin } from '../OverGridImagePlugin';--export function SetImageType(plugin: OverGridImagePlugin, sheetId: string, id: string, type: string): string {- let options = plugin.getConfig();- let property = options.value;- let find = null;- for (let i = 0; i < property.length; i++) {- let element = property[i];- if (element.sheetId === sheetId && id === element.id) {- find = element;- break;- }- }- if (find) {- const old = find.type;- find.type = type;- return old;- }- return String();-}diff --git a/packages/sheets-plugin-image/src/Apply/index.ts b/packages/sheets-plugin-image/src/Apply/index.tsdeleted file mode 100644index f3326ec12c..0000000000--- a/packages/sheets-plugin-image/src/Apply/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from './SetImageType';diff --git a/packages/sheets-plugin-image/src/Const/ACTION_NAMES.ts b/packages/sheets-plugin-image/src/Basics/Const/ACTION_NAMES.tssimilarity index 100%rename from packages/sheets-plugin-image/src/Const/ACTION_NAMES.tsrename to packages/sheets-plugin-image/src/Basics/Const/ACTION_NAMES.tsdiff --git a/packages/sheets-plugin-image/src/Const/PLUGIN_NAME.ts b/packages/sheets-plugin-image/src/Basics/Const/PLUGIN_NAME.tssimilarity index 100%rename from packages/sheets-plugin-image/src/Const/PLUGIN_NAME.tsrename to packages/sheets-plugin-image/src/Basics/Const/PLUGIN_NAME.tsdiff --git a/packages/sheets-plugin-image/src/Const/index.ts b/packages/sheets-plugin-image/src/Basics/Const/index.tssimilarity index 50%rename from packages/sheets-plugin-image/src/Const/index.tsrename to packages/sheets-plugin-image/src/Basics/Const/index.tsindex 3cc114295e..a1f79b393d 100644--- a/packages/sheets-plugin-image/src/Const/index.ts+++ b/packages/sheets-plugin-image/src/Basics/Const/index.ts@@ -1 +1,2 @@export * from './ACTION_NAMES';+export * from './PLUGIN_NAME';diff --git a/packages/sheets-plugin-image/src/Enum/BorderType.ts b/packages/sheets-plugin-image/src/Basics/Enum/BorderType.tssimilarity index 100%rename from packages/sheets-plugin-image/src/Enum/BorderType.tsrename to packages/sheets-plugin-image/src/Basics/Enum/BorderType.tsdiff --git a/packages/sheets-plugin-image/src/Enum/NormalType.ts b/packages/sheets-plugin-image/src/Basics/Enum/NormalType.tssimilarity index 100%rename from packages/sheets-plugin-image/src/Enum/NormalType.tsrename to packages/sheets-plugin-image/src/Basics/Enum/NormalType.tsdiff --git a/packages/sheets-plugin-image/src/Basics/Enum/index.ts b/packages/sheets-plugin-image/src/Basics/Enum/index.tsnew file mode 100644index 0000000000..916092d75e--- /dev/null+++ b/packages/sheets-plugin-image/src/Basics/Enum/index.ts@@ -0,0 +1,2 @@+export * from './BorderType';+export * from './NormalType';diff --git a/packages/sheets-plugin-image/src/IData.ts b/packages/sheets-plugin-image/src/Basics/Interfaces/IData.tssimilarity index 64%rename from packages/sheets-plugin-image/src/IData.tsrename to packages/sheets-plugin-image/src/Basics/Interfaces/IData.tsindex 75b4de21aa..868a1d2a62 100644--- a/packages/sheets-plugin-image/src/IData.ts+++ b/packages/sheets-plugin-image/src/Basics/Interfaces/IData.ts@@ -1,5 +1,4 @@-import { BorderType } from './Enum/BorderType';-import { NormalType } from './Enum/NormalType';+import { BorderType, NormalType } from '../Enum';export type IProps = {normal: NormalType;diff --git a/packages/sheets-plugin-image/src/Basics/Interfaces/IOverGridImagePluginConfig.ts b/packages/sheets-plugin-image/src/Basics/Interfaces/IOverGridImagePluginConfig.tsnew file mode 100644index 0000000000..60ff391df5--- /dev/null+++ b/packages/sheets-plugin-image/src/Basics/Interfaces/IOverGridImagePluginConfig.ts@@ -0,0 +1 @@+export interface IOverGridImagePluginConfig {}diff --git a/packages/sheets-plugin-image/src/Basics/Interfaces/IOverGridImageProperty.ts b/packages/sheets-plugin-image/src/Basics/Interfaces/IOverGridImageProperty.tsnew file mode 100644index 0000000000..4491675718--- /dev/null+++ b/packages/sheets-plugin-image/src/Basics/Interfaces/IOverGridImageProperty.ts@@ -0,0 +1,21 @@+import { IPictureProps } from '@univerjs/base-render';++export enum OverGridImageBorderType {+ DASHED,+ SOLID,+ DOUBLE,+}++export interface IOverGridImageProperty extends IPictureProps {+ id: string;+ sheetId: string;+ radius: number;+ url: string;+ borderType: OverGridImageBorderType;+ width: number;+ height: number;+ row: number;+ column: number;+ borderColor: string;+ borderWidth: number;+}diff --git a/packages/sheets-plugin-image/src/Basics/Interfaces/index.ts b/packages/sheets-plugin-image/src/Basics/Interfaces/index.tsnew file mode 100644index 0000000000..3cd80b9e86--- /dev/null+++ b/packages/sheets-plugin-image/src/Basics/Interfaces/index.ts@@ -0,0 +1,3 @@+export * from './IOverGridImagePluginConfig';+export * from './IOverGridImageProperty';+export * from './IData';diff --git a/packages/sheets-plugin-image/src/Library/FileSelected.ts b/packages/sheets-plugin-image/src/Basics/Library/FileSelected.tssimilarity index 100%rename from packages/sheets-plugin-image/src/Library/FileSelected.tsrename to packages/sheets-plugin-image/src/Basics/Library/FileSelected.tsdiff --git a/packages/sheets-plugin-image/src/Basics/Library/index.ts b/packages/sheets-plugin-image/src/Basics/Library/index.tsnew file mode 100644index 0000000000..8af4b57205--- /dev/null+++ b/packages/sheets-plugin-image/src/Basics/Library/index.ts@@ -0,0 +1 @@+export * from './FileSelected';diff --git a/packages/sheets-plugin-image/src/Basics/Observer.ts b/packages/sheets-plugin-image/src/Basics/Observer.tsindex d91325c92c..2cbd7ee348 100644--- a/packages/sheets-plugin-image/src/Basics/Observer.ts+++ b/packages/sheets-plugin-image/src/Basics/Observer.ts@@ -1,15 +1,16 @@import { Observable } from '@univerjs/core';-import { OverGridImagePlugin, OverGridImageProperty } from '../OverGridImagePlugin';+import { ImagePlugin } from '../ImagePlugin';+import { IOverGridImageProperty } from './Interfaces';export type ImagePluginObserve = {- onChangeImageSize: Observable<OverGridImageProperty>;- onAddImage: Observable<OverGridImageProperty>;- onRemoveImage: Observable<OverGridImageProperty>;- onUpdateImage: Observable<OverGridImageProperty>;- onActiveImage: Observable<OverGridImageProperty>;+ onChangeImageSize: Observable<IOverGridImageProperty>;+ onAddImage: Observable<IOverGridImageProperty>;+ onRemoveImage: Observable<IOverGridImageProperty>;+ onUpdateImage: Observable<IOverGridImageProperty>;+ onActiveImage: Observable<IOverGridImageProperty>;};-export function uninstall(plugin: OverGridImagePlugin) {+export function uninstall(plugin: ImagePlugin) {plugin.deleteObserve('onChangeImageSize');plugin.deleteObserve('onAddImage');plugin.deleteObserve('onRemoveImage');@@ -17,7 +18,7 @@ export function uninstall(plugin: OverGridImagePlugin) {plugin.deleteObserve('onActiveImage');}-export function install(plugin: OverGridImagePlugin) {+export function install(plugin: ImagePlugin) {plugin.pushToObserve('onChangeImageSize');plugin.pushToObserve('onAddImage');plugin.pushToObserve('onRemoveImage');diff --git a/packages/sheets-plugin-image/src/Basics/index.ts b/packages/sheets-plugin-image/src/Basics/index.tsnew file mode 100644index 0000000000..2cf8dd61f0--- /dev/null+++ b/packages/sheets-plugin-image/src/Basics/index.ts@@ -0,0 +1,5 @@+export * from './Const';+export * from './Enum';+export * from './Interfaces';+export * from './Library';+export * from './Observer';diff --git a/packages/sheets-plugin-image/src/Command/Action/AddImagePropertyAction.ts b/packages/sheets-plugin-image/src/Command/Action/AddImagePropertyAction.tsdeleted file mode 100644index 0c0b29a76f..0000000000--- a/packages/sheets-plugin-image/src/Command/Action/AddImagePropertyAction.ts+++ /dev/null@@ -1,76 +0,0 @@-import { SheetActionBase, ActionObservers, ISheetActionData, Workbook } from '@univerjs/core';-import { ACTION_NAMES } from '../../Const';-import { OverGridImageBorderType, OverGridImagePlugin } from '../../OverGridImagePlugin';-import { AddImageProperty } from '../../Apply/AddImageProperty';-import { RemoveImageProperty } from '../../Apply/RemoveImageProperty';-import { OVER_GRID_IMAGE_PLUGIN_NAME } from '../../Const/PLUGIN_NAME';--export interface IAddImageProperty extends ISheetActionData {- id?: string;- sheetId: string;- radius: number;- url: string;- borderType: OverGridImageBorderType;- width: number;- height: number;- row: number;- column: number;- borderColor: string;- borderWidth: number;-}--export class AddImagePropertyAction extends SheetActionBase<IAddImageProperty, IAddImageProperty> {- constructor(actionData: IAddImageProperty, workbook: Workbook, observers: ActionObservers) {- super(actionData, workbook, observers);- this._oldActionData = {- actionName: ACTION_NAMES.SET_IMAGE_TYPE_ACTION,- id: this.do(),- sheetId: actionData.sheetId,- radius: actionData.radius,- url: actionData.url,- borderType: actionData.borderType,- width: actionData.width,- height: actionData.height,- row: actionData.row,- column: actionData.column,- borderColor: actionData.borderColor,- borderWidth: actionData.borderWidth,- };- }-- do(): string {- const worksheet = this.getWorkSheet();- const context = worksheet.getContext();- const manager = context.getPluginManager();- const plugin = manager.getPluginByName(OVER_GRID_IMAGE_PLUGIN_NAME) as OverGridImagePlugin;- return AddImageProperty(plugin, {- id: this._doActionData.id!,- sheetId: this._doActionData.sheetId,- radius: this._doActionData.radius,- url: this._doActionData.url,- borderType: this._doActionData.borderType,- width: this._doActionData.width,- height: this._doActionData.height,- row: this._doActionData.row,- column: this._doActionData.column,- borderColor: this._doActionData.borderColor,- borderWidth: this._doActionData.borderWidth,- });- }-- redo(): void {- this.do();- }-- undo(): void {- const worksheet = this.getWorkSheet();- const context = worksheet.getContext();- const manager = context.getPluginManager();- const plugin = manager.getPluginByName(OVER_GRID_IMAGE_PLUGIN_NAME) as OverGridImagePlugin;- RemoveImageProperty(plugin, this._oldActionData.id!);- }-- validate(): boolean {- return false;- }-}diff --git a/packages/sheets-plugin-image/src/Command/Action/index.ts b/packages/sheets-plugin-image/src/Command/Action/index.tsdeleted file mode 100644index 317f3f3e78..0000000000--- a/packages/sheets-plugin-image/src/Command/Action/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from './SetImageTypeAction';diff --git a/packages/sheets-plugin-image/src/Command/RegisterAction.ts b/packages/sheets-plugin-image/src/Command/RegisterAction.tsdeleted file mode 100644index 7fcaf67173..0000000000--- a/packages/sheets-plugin-image/src/Command/RegisterAction.ts+++ /dev/null@@ -1,7 +0,0 @@-import { CommandManager } from '@univerjs/core';-import { ACTION_NAMES } from '../Const';-import { SetImageTypeAction } from './Action';-import { AddImagePropertyAction } from './Action/AddImagePropertyAction';--CommandManager.register(ACTION_NAMES.SET_IMAGE_TYPE_ACTION, SetImageTypeAction);-CommandManager.register(ACTION_NAMES.ADD_IMAGE_PROPERTY_ACTION, AddImagePropertyAction);diff --git a/packages/sheets-plugin-image/src/Command/index.ts b/packages/sheets-plugin-image/src/Command/index.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/sheets-plugin-image/src/Controller/CellImageController.ts b/packages/sheets-plugin-image/src/Controller/CellImageController.tsnew file mode 100644index 0000000000..f40e493a8a--- /dev/null+++ b/packages/sheets-plugin-image/src/Controller/CellImageController.ts@@ -0,0 +1,8 @@+import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';+import { Inject } from '@wendellhu/redi';++export class CellImageController {+ constructor(@Inject(SheetContainerUIController) private readonly _sheetContainerUIController: SheetContainerUIController) {+ // TODO ...+ }+}diff --git a/packages/sheets-plugin-image/src/Controller/OverGridImageController.ts b/packages/sheets-plugin-image/src/Controller/OverGridImageController.tsindex 9385037cab..97a2eff8f6 100644--- a/packages/sheets-plugin-image/src/Controller/OverGridImageController.ts+++ b/packages/sheets-plugin-image/src/Controller/OverGridImageController.ts@@ -1,32 +1,65 @@import { BaseComponentRender } from '@univerjs/base-ui';-import { IToolbarItemProps, SHEET_UI_PLUGIN_NAME, SheetUIPlugin } from '@univerjs/ui-plugin-sheets';-import { OverGridImagePlugin } from '../OverGridImagePlugin';-import { OVER_GRID_IMAGE_PLUGIN_NAME } from '../Const/PLUGIN_NAME';-import { FileSelected } from '../Library/FileSelected';+import { IToolbarItemProps, SheetContainerUIController } from '@univerjs/ui-plugin-sheets';+import { Inject, Injector } from '@wendellhu/redi';+import { ISelectionManager, SelectionManager } from '@univerjs/base-sheets';+import { Command, CommandManager, ICurrentUniverService, ObserverManager, Tools } from '@univerjs/core';+import { FileSelected, IOverGridImageProperty, OVER_GRID_IMAGE_PLUGIN_NAME, OverGridImageBorderType } from '../Basics';+import { IImagePluginData } from '../Symbol';+import { AddOverGridImageAction, IAddOverGridImageActionData } from '../Model';export class OverGridImageController {- protected _sheetUIPlugin: SheetUIPlugin;-- protected _plugin: OverGridImagePlugin;-protected _render: BaseComponentRender;protected _toolButton: IToolbarItemProps;- constructor(plugin: OverGridImagePlugin) {- this._plugin = plugin;- this._sheetUIPlugin = plugin.getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);-+ constructor(+ @Inject(Injector) readonly _injector: Injector,+ @Inject(IImagePluginData) _imagePluginData: Map<string, IOverGridImageProperty>,+ @Inject(SheetContainerUIController) private readonly _sheetContainerUIController: SheetContainerUIController,+ @Inject(CommandManager) private _commandManager: CommandManager,+ @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,+ @Inject(ObserverManager) private _observerManager: ObserverManager,+ @ISelectionManager private readonly _selectionManager: SelectionManager+ ) {this._toolButton = {name: OVER_GRID_IMAGE_PLUGIN_NAME,+ label: '图片',toolbarType: 1,- tooltip: '导入图片',show: true,- label: '图片',+ tooltip: '导入图片',onClick: () => {- FileSelected.chooseImage().then((img) => {});+ const rowIndex = _selectionManager.getActiveRange()?.getRowIndex();+ const columnIndex = _selectionManager.getActiveRange()?.getColumn();+ const workbook = _currentUniverService.getCurrentUniverSheetInstance().getWorkBook();+ FileSelected.chooseImage().then((file) => {+ const reader = new FileReader();+ const img = new Image();+ reader.readAsDataURL(file);+ reader.onload = () => {+ img.src = reader.result as string;+ };+ img.onload = () => {+ const action: IAddOverGridImageActionData = {+ actionName: AddOverGridImageAction.NAME,+ id: Tools.generateRandomId(),+ borderType: OverGridImageBorderType.SOLID,+ row: rowIndex || 1,+ column: columnIndex || 1,+ url: img.src,+ radius: 0,+ width: img.width,+ height: img.height,+ borderColor: '#000000',+ borderWidth: 1,+ sheetId: workbook.getActiveSheet().getSheetId(),+ injector: _injector,+ };+ const command = new Command({ WorkBookUnit: workbook }, action);+ this._commandManager.invoke(command);+ };+ });},};- this._sheetUIPlugin.addToolButton(this._toolButton);+ this._sheetContainerUIController.getToolbarController().addToolbarConfig(this._toolButton);}}diff --git a/packages/sheets-plugin-image/src/Controller/index.ts b/packages/sheets-plugin-image/src/Controller/index.tsnew file mode 100644index 0000000000..d1626709ab--- /dev/null+++ b/packages/sheets-plugin-image/src/Controller/index.ts@@ -0,0 +1,2 @@+export * from './CellImageController';+export * from './OverGridImageController';diff --git a/packages/sheets-plugin-image/src/Enum/index.ts b/packages/sheets-plugin-image/src/Enum/index.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/sheets-plugin-image/src/ImagePlugin.tsx b/packages/sheets-plugin-image/src/ImagePlugin.tsxnew file mode 100644index 0000000000..1acb9cb51f--- /dev/null+++ b/packages/sheets-plugin-image/src/ImagePlugin.tsx@@ -0,0 +1,59 @@+import { Plugin, PluginType, CommandManager, LocaleService } from '@univerjs/core';+import { Dependency, Inject, Injector } from '@wendellhu/redi';+import { uninstall } from '@univerjs/base-sheets';+import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';+import { OverImageRender } from './View/Render';+import { IImagePluginData } from './Symbol';+import { OVER_GRID_IMAGE_PLUGIN_NAME, IOverGridImagePluginConfig, IOverGridImageProperty, install } from './Basics';+import { OverGridImageController, CellImageController } from './Controller';++/**+ * TODO: 考虑加入单元格图片的情况,+ *+ * 如果工具栏的“插入单元格图片”“插入浮动图片”是在一个按钮的下拉列表里,那么UI部分是重叠的,所以这里应该叫 ImagePlugin,下面再细分 OverGridImage 和 CellImage+ *+ */+export class ImagePlugin extends Plugin {+ static override type = PluginType.Sheet;++ protected _overGridImageController: OverGridImageController;++ protected _overImageRender: OverImageRender;++ protected _imagePluginData: Map<string, IOverGridImageProperty>;++ protected _cellImageController: CellImageController;++ constructor(+ private _config: IOverGridImagePluginConfig,+ @Inject(Injector) override readonly _injector: Injector,+ @Inject(LocaleService) private readonly _localeService: LocaleService,+ @Inject(CommandManager) private readonly _commandManager: CommandManager+ ) {+ super(OVER_GRID_IMAGE_PLUGIN_NAME);+ this._imagePluginData = new Map<string, IOverGridImageProperty>();+ this._injector.add([IImagePluginData, { useFactory: () => this._imagePluginData }]);+ }++ override onMounted(): void {+ install(this);+ const sheetContainerUIController = this._injector.get(SheetContainerUIController);+ sheetContainerUIController.UIDidMount(() => {+ this._initializeDependencies(this._injector);+ });+ }++ override onDestroy(): void {+ uninstall(this);+ }++ private _initializeDependencies(sheetInjector: Injector) {+ const dependencies: Dependency[] = [[OverGridImageController], [CellImageController], [OverImageRender]];+ dependencies.forEach((d) => {+ sheetInjector.add(d);+ });+ this._overImageRender = sheetInjector.createInstance(OverImageRender);+ this._cellImageController = sheetInjector.createInstance(CellImageController);+ this._overGridImageController = sheetInjector.createInstance(OverGridImageController);+ }+}diff --git a/packages/sheets-plugin-image/src/Model/Action/AddOverGridImageAction.ts b/packages/sheets-plugin-image/src/Model/Action/AddOverGridImageAction.tsnew file mode 100644index 0000000000..71e56d1a5b--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/Action/AddOverGridImageAction.ts@@ -0,0 +1,59 @@+import { SheetActionBase, ActionObservers, ISheetActionData, CommandUnit, ActionType } from '@univerjs/core';+import { ACTION_NAMES, OverGridImageBorderType } from '../../Basics';+import { AddOverGridImageApply, RemoveOverGridImageApply } from '../Apply';+import { IRemoveOverGridImageActionData } from './RemoveOverGridImageAction';++export interface IAddOverGridImageActionData extends ISheetActionData {+ id: string;+ sheetId: string;+ radius: number;+ url: string;+ borderType: OverGridImageBorderType;+ width: number;+ height: number;+ row: number;+ column: number;+ borderColor: string;+ borderWidth: number;+}++export class AddOverGridImageAction extends SheetActionBase<IAddOverGridImageActionData, IRemoveOverGridImageActionData> {+ static NAME = 'AddImagePropertyAction';++ constructor(actionData: IAddOverGridImageActionData, commandUnit: CommandUnit, observers: ActionObservers) {+ super(actionData, commandUnit, observers);+ this._oldActionData = {+ actionName: ACTION_NAMES.SET_IMAGE_TYPE_ACTION,+ id: this.do(),+ sheetId: actionData.sheetId,+ injector: actionData.injector,+ };+ }++ do(): string {+ const result = AddOverGridImageApply(this._doActionData);+ this._observers.notifyObservers({+ type: ActionType.REDO,+ data: this._doActionData,+ action: this,+ });+ return result;+ }++ redo(): void {+ this.do();+ }++ undo(): void {+ RemoveOverGridImageApply(this._oldActionData);+ this._observers.notifyObservers({+ type: ActionType.UNDO,+ data: this._oldActionData,+ action: this,+ });+ }++ validate(): boolean {+ return false;+ }+}diff --git a/packages/sheets-plugin-image/src/Model/Action/RemoveOverGridImageAction.ts b/packages/sheets-plugin-image/src/Model/Action/RemoveOverGridImageAction.tsnew file mode 100644index 0000000000..79c815d45d--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/Action/RemoveOverGridImageAction.ts@@ -0,0 +1,45 @@+import { ActionObservers, CommandUnit, CommonParameter, ISheetActionData, SheetActionBase } from '@univerjs/core';+import { IAddOverGridImageActionData } from './AddOverGridImageAction';+import { OverGridImageBorderType } from '../../Basics';++export interface IRemoveOverGridImageActionData extends ISheetActionData {+ id: string;+}++export class RemoveOverGridImageAction extends SheetActionBase<IRemoveOverGridImageActionData, IAddOverGridImageActionData> {+ static NAME = 'RemoveOverGridImageAction';++ constructor(actionData: IRemoveOverGridImageActionData, commandUnit: CommandUnit, observers: ActionObservers) {+ super(actionData, commandUnit, observers);+ this._oldActionData = {+ id: '',+ actionName: '',+ sheetId: '',+ radius: 0,+ url: '',+ borderType: OverGridImageBorderType.SOLID,+ width: 0,+ height: 0,+ row: 0,+ column: 0,+ borderColor: '',+ borderWidth: 0,+ };+ }++ override redo(commonParameter?: CommonParameter | undefined): void {+ throw new Error('Method not implemented.');+ }++ override undo(commonParameter?: CommonParameter | undefined): void {+ throw new Error('Method not implemented.');+ }++ override do(commonParameter?: CommonParameter | undefined): void {+ throw new Error('Method not implemented.');+ }++ override validate(): boolean {+ throw new Error('Method not implemented.');+ }+}diff --git a/packages/sheets-plugin-image/src/Command/Action/SetImageTypeAction.ts b/packages/sheets-plugin-image/src/Model/Action/SetOverGridImageTypeAction.tssimilarity index 60%rename from packages/sheets-plugin-image/src/Command/Action/SetImageTypeAction.tsrename to packages/sheets-plugin-image/src/Model/Action/SetOverGridImageTypeAction.tsindex 4c3234f3cc..e33f5a6b03 100644--- a/packages/sheets-plugin-image/src/Command/Action/SetImageTypeAction.ts+++ b/packages/sheets-plugin-image/src/Model/Action/SetOverGridImageTypeAction.ts@@ -1,8 +1,6 @@-import { SheetActionBase, ActionObservers, ISheetActionData, Workbook } from '@univerjs/core';-import { SetImageType } from '../../Apply';-import { OverGridImagePlugin } from '../../OverGridImagePlugin';-import { ACTION_NAMES } from '../../Const';-import { OVER_GRID_IMAGE_PLUGIN_NAME } from '../../Const/PLUGIN_NAME';+import { SheetActionBase, ActionObservers, ISheetActionData, CommandUnit } from '@univerjs/core';+import { SetOverGridImageTypeApply } from '../Apply';+import { ACTION_NAMES, OVER_GRID_IMAGE_PLUGIN_NAME } from '../../Basics';export interface ISetImageTypeData extends ISheetActionData {id: string;@@ -10,8 +8,10 @@ export interface ISetImageTypeData extends ISheetActionData {}export class SetImageTypeAction extends SheetActionBase<ISetImageTypeData, ISetImageTypeData> {- constructor(actionData: ISetImageTypeData, workbook: Workbook, observers: ActionObservers) {- super(actionData, workbook, observers);+ static NAME = 'SetImageTypeAction';++ constructor(actionData: ISetImageTypeData, commandUnit: CommandUnit, observers: ActionObservers) {+ super(actionData, commandUnit, observers);this._oldActionData = {actionName: ACTION_NAMES.SET_IMAGE_TYPE_ACTION,id: actionData.id,@@ -29,7 +29,7 @@ export class SetImageTypeAction extends SheetActionBase<ISetImageTypeData, ISetIconst context = worksheet.getContext();const manager = context.getPluginManager();const plugin = manager.getPluginByName(OVER_GRID_IMAGE_PLUGIN_NAME) as OverGridImagePlugin;- return SetImageType(plugin, this._doActionData.sheetId, this._doActionData.id, this._doActionData.type);+ return SetOverGridImageTypeApply(plugin, this._doActionData.sheetId, this._doActionData.id, this._doActionData.type);}undo(): void {@@ -37,7 +37,7 @@ export class SetImageTypeAction extends SheetActionBase<ISetImageTypeData, ISetIconst context = worksheet.getContext();const manager = context.getPluginManager();const plugin = manager.getPluginByName(OVER_GRID_IMAGE_PLUGIN_NAME) as OverGridImagePlugin;- SetImageType(plugin, this._oldActionData.sheetId, this._oldActionData.id, this._oldActionData.type);+ SetOverGridImageTypeApply(plugin, this._oldActionData.sheetId, this._oldActionData.id, this._oldActionData.type);}validate(): boolean {diff --git a/packages/sheets-plugin-image/src/Model/Action/index.ts b/packages/sheets-plugin-image/src/Model/Action/index.tsnew file mode 100644index 0000000000..22f69f4fa8--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/Action/index.ts@@ -0,0 +1,3 @@+export * from './SetOverGridImageTypeAction';+export * from './AddOverGridImageAction';+export * from './RemoveOverGridImageAction';diff --git a/packages/sheets-plugin-image/src/Model/Apply/AddOverGridImageApply.ts b/packages/sheets-plugin-image/src/Model/Apply/AddOverGridImageApply.tsnew file mode 100644index 0000000000..ab6d8e160a--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/Apply/AddOverGridImageApply.ts@@ -0,0 +1,24 @@+import { IImagePluginData } from '../../Symbol';+import { IAddOverGridImageActionData } from '../Action';++export function AddOverGridImageApply(property: IAddOverGridImageActionData): string {+ const injector = property.injector;+ if (injector == null) {+ throw new Error('Error injector is null');+ }+ const imagePluginData = injector.get(IImagePluginData);+ imagePluginData.set(property.id, {+ id: property.id,+ sheetId: property.sheetId,+ radius: property.radius,+ url: property.url,+ borderType: property.borderType,+ width: property.width,+ height: property.height,+ row: property.row,+ column: property.column,+ borderColor: property.borderColor,+ borderWidth: property.borderWidth,+ });+ return property.id;+}diff --git a/packages/sheets-plugin-image/src/Model/Apply/RemoveOverGridImageApply.ts b/packages/sheets-plugin-image/src/Model/Apply/RemoveOverGridImageApply.tsnew file mode 100644index 0000000000..f85ad04a57--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/Apply/RemoveOverGridImageApply.ts@@ -0,0 +1,11 @@+import { IImagePluginData } from '../../Symbol';+import { IRemoveOverGridImageActionData } from '../Action';++export function RemoveOverGridImageApply(property: IRemoveOverGridImageActionData): void {+ const injector = property.injector;+ if (injector == null) {+ throw new Error('Error injector is null');+ }+ const imagePluginData = injector.get(IImagePluginData);+ imagePluginData.delete(property.id);+}diff --git a/packages/sheets-plugin-image/src/Model/Apply/SetOverGridImageTypeApply.ts b/packages/sheets-plugin-image/src/Model/Apply/SetOverGridImageTypeApply.tsnew file mode 100644index 0000000000..ff3ecff548--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/Apply/SetOverGridImageTypeApply.ts@@ -0,0 +1 @@+export function SetOverGridImageTypeApply(sheetId: string, id: string, type: string): string {}diff --git a/packages/sheets-plugin-image/src/Model/Apply/index.ts b/packages/sheets-plugin-image/src/Model/Apply/index.tsnew file mode 100644index 0000000000..1b8a70f464--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/Apply/index.ts@@ -0,0 +1,3 @@+export * from './AddOverGridImageApply';+export * from './RemoveOverGridImageApply';+export * from './SetOverGridImageTypeApply';diff --git a/packages/sheets-plugin-image/src/Model/index.ts b/packages/sheets-plugin-image/src/Model/index.tsnew file mode 100644index 0000000000..feeb9b6136--- /dev/null+++ b/packages/sheets-plugin-image/src/Model/index.ts@@ -0,0 +1,2 @@+export * from './Action';+export * from './Apply';diff --git a/packages/sheets-plugin-image/src/OverGridImagePlugin.tsx b/packages/sheets-plugin-image/src/OverGridImagePlugin.tsxdeleted file mode 100644index ed321c57bc..0000000000--- a/packages/sheets-plugin-image/src/OverGridImagePlugin.tsx+++ /dev/null@@ -1,138 +0,0 @@-import { Command, Plugin, Nullable, Worksheet, UniverSheet } from '@univerjs/core';-import { IPictureProps } from '@univerjs/base-render';-import { ACTION_NAMES } from './Const';-import { ImagePluginObserve, install, uninstall } from './Basics/Observer';-import { OVER_GRID_IMAGE_PLUGIN_NAME } from './Const/PLUGIN_NAME';-import { OverImageRender } from './View/OverImageRender';-import './Command/RegisterAction';-import { OverGridImageController } from './Controller/OverGridImageController';--export enum OverGridImageBorderType {- DASHED,- SOLID,- DOUBLE,-}--export interface OverGridImageProperty extends IPictureProps {- id: string;- sheetId: string;- radius: number;- url: string;- borderType: OverGridImageBorderType;- width: number;- height: number;- row: number;- column: number;- borderColor: string;- borderWidth: number;-}--export interface IOverGridImagePluginConfig {- value: OverGridImageProperty[];-}--export class OverGridImage {- protected readonly _property: OverGridImageProperty;-- protected readonly _plugin: Plugin;-- constructor(plugin: Plugin, property: OverGridImageProperty) {- this._plugin = plugin;- this._property = property;- }-- getAltTextDescription(): string {- return '';- }-- getHeight(): number {- return this._property.height;- }-- getAltTextTitle(): string {- return '';- }-- getProperty(): OverGridImageProperty {- return this._property;- }-- getPlugin(): Plugin {- return this._plugin;- }-- getSheet(): Nullable<Worksheet> {- return this.getPlugin().getUniver().getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(this._property.sheetId);- }-- setHeight(height: number): void {- const manager = this.getPlugin().getContext().getCommandManager();- const workbook = this.getPlugin().getUniver().getCurrentUniverSheetInstance().getWorkBook();- const configure = {- actionName: ACTION_NAMES.SET_IMAGE_TYPE_ACTION,- sheetId: this._property.sheetId,- };- const command = new Command(- {- WorkBookUnit: workbook,- },- configure- );- manager.invoke(command);- }-}--/**- * TODO: 考虑加入单元格图片的情况,- *- * 如果工具栏的“插入单元格图片”“插入浮动图片”是在一个按钮的下拉列表里,那么UI部分是重叠的,所以这里应该叫 ImagePlugin,下面再细分 OverGridImage 和 CellImage- *- */-export class OverGridImagePlugin extends Plugin<ImagePluginObserve> {- protected _config: IOverGridImagePluginConfig;-- protected _render: OverImageRender;-- protected _overGridImageController: OverGridImageController;-- constructor(config: IOverGridImagePluginConfig = { value: [] }) {- super(OVER_GRID_IMAGE_PLUGIN_NAME);- this._config = config;- }-- static create(config: IOverGridImagePluginConfig): OverGridImagePlugin {- return new OverGridImagePlugin(config);- }-- installTo(univerSheetInstance: UniverSheet): void {- univerSheetInstance.installPlugin(this);- }-- onMounted(): void {- install(this);- this._overGridImageController = new OverGridImageController(this);- this._render = new OverImageRender(this);- }-- onDestroy(): void {- uninstall(this);- }-- hideOverImagePanel(): void {- // const plugin: SheetPlugin = this.getPluginByName(PLUGIN_NAMES.SPREADSHEET)!;- // plugin.showSiderByName(OVER_GRID_IMAGE_PLUGIN_NAME, false);- }-- showOverImagePanel(): void {- // const plugin: SheetPlugin = this.getPluginByName(PLUGIN_NAMES.SPREADSHEET)!;- // plugin.showSiderByName(OVER_GRID_IMAGE_PLUGIN_NAME, true);- }-- getConfig(): IOverGridImagePluginConfig {- return this._config;- }-- getOverGridImages(): OverGridImage[] {- return this._config.value.map((element) => new OverGridImage(this, element));- }-}diff --git a/packages/sheets-plugin-image/src/RegisterAction.ts b/packages/sheets-plugin-image/src/RegisterAction.tsnew file mode 100644index 0000000000..21beaf35e5--- /dev/null+++ b/packages/sheets-plugin-image/src/RegisterAction.ts@@ -0,0 +1,6 @@+import { CommandManager } from '@univerjs/core';+import { AddOverGridImageAction, RemoveOverGridImageAction, SetImageTypeAction } from './Model';++CommandManager.register(SetImageTypeAction.NAME, SetImageTypeAction);+CommandManager.register(AddOverGridImageAction.NAME, AddOverGridImageAction);+CommandManager.register(RemoveOverGridImageAction.NAME, RemoveOverGridImageAction);diff --git a/packages/sheets-plugin-image/src/Symbol/index.ts b/packages/sheets-plugin-image/src/Symbol/index.tsnew file mode 100644index 0000000000..639aff4ac0--- /dev/null+++ b/packages/sheets-plugin-image/src/Symbol/index.ts@@ -0,0 +1,4 @@+import { createIdentifier } from '@wendellhu/redi';+import { IOverGridImageProperty } from '../Basics';++export const IImagePluginData = createIdentifier<Map<string, IOverGridImageProperty>>('image-plugin-data');diff --git a/packages/sheets-plugin-image/src/View/OverImageRender.ts b/packages/sheets-plugin-image/src/View/OverImageRender.tsdeleted file mode 100644index 2297d95586..0000000000--- a/packages/sheets-plugin-image/src/View/OverImageRender.ts+++ /dev/null@@ -1,55 +0,0 @@-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: number = 1000;-- private _mainScene: Scene;-- private _plugin: OverGridImagePlugin;-- private _activeShape: OverImageShape;-- constructor(plugin: OverGridImagePlugin) {- 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) => {- eventData.autoWidth = true;- eventData.autoHeight = true;- this.addOverImage(eventData);- });- }-- addOverImage(property: OverGridImageProperty): void {- const shape = new OverImageShape(property);- shape.on(EVENT_TYPE.PointerDown, () => {- this._activeShape = shape;- this._plugin.showOverImagePanel();- this._plugin.getObserver('onActiveImage')!.notifyObservers(shape.getProperty());- });- this._mainScene.addObject(shape, OverImageRender.LAYER_Z_INDEX);- }-- removeOverImage(id: string): void {- const layer = this._mainScene.getLayer(OverImageRender.LAYER_Z_INDEX);- if (layer != null) {- let readyRemove = [];- let layerObject = layer.getObjects();- for (let i = 0; i < layerObject.length; i++) {- const shape = layerObject[i] as OverImageShape;- if (shape.getProperty().id === id) {- readyRemove.push(shape);- }- }- for (let i = 0; i < readyRemove.length; i++) {- const shape = layerObject[i] as OverImageShape;- layer.removeObject(shape);- }- }- }-}diff --git a/packages/sheets-plugin-image/src/View/Render/OverImageRender.ts b/packages/sheets-plugin-image/src/View/Render/OverImageRender.tsnew file mode 100644index 0000000000..61ad0e5293--- /dev/null+++ b/packages/sheets-plugin-image/src/View/Render/OverImageRender.ts@@ -0,0 +1,57 @@+import { Scene, IRenderingEngine } from '@univerjs/base-render';+import { CommandManager, ObserverManager } from '@univerjs/core';+import { Inject, Injector } from '@wendellhu/redi';+import { OverImageShape } from './OverImageShape';+import { IOverGridImageProperty } from '../../Basics';+import { AddOverGridImageAction, IAddOverGridImageActionData, IRemoveOverGridImageActionData, RemoveOverGridImageAction } from '../../Model';++export class OverImageRender {+ static LAYER_Z_INDEX: number = 1000;++ private _mainScene: Scene;++ constructor(@Inject(Injector) readonly _injector: Injector, @Inject(ObserverManager) private _observerManager: ObserverManager) {+ const engine = _injector.get(IRenderingEngine);+ this._mainScene = engine.getScene('mainScene') as Scene;+ if (this._mainScene == null) {+ throw new Error('main scene is null !!');+ }+ CommandManager.getActionObservers().add((event) => {+ switch (event.data.actionName) {+ case AddOverGridImageAction.NAME: {+ const data = event.data as IAddOverGridImageActionData;+ this.addOverImage(data);+ break;+ }+ case RemoveOverGridImageAction.NAME: {+ const data = event.data as IRemoveOverGridImageActionData;+ this.removeOverImage(data.id);+ break;+ }+ }+ });+ }++ addOverImage(property: IOverGridImageProperty): void {+ const shape = new OverImageShape(property);+ this._mainScene.addObject(shape, OverImageRender.LAYER_Z_INDEX);+ }++ removeOverImage(id: string): void {+ const layer = this._mainScene.getLayer(OverImageRender.LAYER_Z_INDEX);+ if (layer != null) {+ const readyRemove = [];+ const layerObject = layer.getObjects();+ for (let i = 0; i < layerObject.length; i++) {+ const shape = layerObject[i] as OverImageShape;+ if (shape.getProperty().id === id) {+ readyRemove.push(shape);+ }+ }+ for (let i = 0; i < readyRemove.length; i++) {+ const shape = layerObject[i] as OverImageShape;+ layer.removeObject(shape);+ }+ }+ }+}diff --git a/packages/sheets-plugin-image/src/View/OverImageShape.ts b/packages/sheets-plugin-image/src/View/Render/OverImageShape.tssimilarity index 90%rename from packages/sheets-plugin-image/src/View/OverImageShape.tsrename to packages/sheets-plugin-image/src/View/Render/OverImageShape.tsindex b44d0c2a19..9c54cea38e 100644--- a/packages/sheets-plugin-image/src/View/OverImageShape.ts+++ b/packages/sheets-plugin-image/src/View/Render/OverImageShape.ts@@ -1,10 +1,10 @@import { Picture } from '@univerjs/base-render';-import { OverGridImageBorderType, OverGridImageProperty } from '../OverGridImagePlugin';+import { IOverGridImageProperty, OverGridImageBorderType } from '../../Basics';export class OverImageShape extends Picture {- protected _property: OverGridImageProperty;+ protected _property: IOverGridImageProperty;- constructor(property: OverGridImageProperty) {+ constructor(property: IOverGridImageProperty) {super(property.id, property);this._property = property;}@@ -69,7 +69,7 @@ export class OverImageShape extends Picture {ctx.stroke();}- static drawWith(ctx: CanvasRenderingContext2D, shape: OverImageShape): void {+ static override drawWith(ctx: CanvasRenderingContext2D, shape: OverImageShape): void {const { borderType } = shape.getProperty();switch (borderType) {case OverGridImageBorderType.SOLID: {@@ -87,11 +87,11 @@ export class OverImageShape extends Picture {}}- getProperty(): OverGridImageProperty {+ getProperty(): IOverGridImageProperty {return this._property;}- protected _draw(ctx: CanvasRenderingContext2D) {+ protected override _draw(ctx: CanvasRenderingContext2D) {OverImageShape.drawWith(ctx, this);super._draw(ctx);}diff --git a/packages/sheets-plugin-image/src/View/Render/index.ts b/packages/sheets-plugin-image/src/View/Render/index.tsnew file mode 100644index 0000000000..3764c92896--- /dev/null+++ b/packages/sheets-plugin-image/src/View/Render/index.ts@@ -0,0 +1,2 @@+export * from './OverImageRender';+export * from './OverImageShape';diff --git a/packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.module.less b/packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.module.lesssimilarity index 100%rename from packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.module.lessrename to packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.module.lessdiff --git a/packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.tsx b/packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.tsxsimilarity index 95%rename from packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.tsxrename to packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.tsxindex 28ad5bb1f3..8e51931ca7 100644--- a/packages/sheets-plugin-image/src/UI/ImagePanel/ImagePanelUI.tsx+++ b/packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.tsx@@ -1,10 +1,6 @@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';-+import { BorderType, NormalType } from '../../../Basics';import Style from './ImagePanelUI.module.less';-import { OverGridImagePlugin } from '../../OverGridImagePlugin';export interface ImagePanelUIProps {normal: NormalType;diff --git a/packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.module.less b/packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.module.lesssimilarity index 100%rename from packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.module.lessrename to packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.module.lessdiff --git a/packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.tsx b/packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.tsxsimilarity index 100%rename from packages/sheets-plugin-image/src/UI/ImageUploadButton/ImageUploadButtonUI.tsxrename to packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.tsxdiff --git a/packages/sheets-plugin-image/src/index.ts b/packages/sheets-plugin-image/src/index.tsindex d1c9381bec..641bfc8114 100644--- a/packages/sheets-plugin-image/src/index.ts+++ b/packages/sheets-plugin-image/src/index.ts@@ -1 +1,3 @@-export { OverGridImagePlugin } from './OverGridImagePlugin';+import './RegisterAction';++export { ImagePlugin } from './ImagePlugin';diff --git a/packages/sheets-plugin-numfmt/src/Basics/Register/NumfmtActionExtension.ts b/packages/sheets-plugin-numfmt/src/Basics/Register/NumfmtActionExtension.tsindex 0e0ad211fa..f288f23b40 100644--- a/packages/sheets-plugin-numfmt/src/Basics/Register/NumfmtActionExtension.ts+++ b/packages/sheets-plugin-numfmt/src/Basics/Register/NumfmtActionExtension.ts@@ -12,18 +12,20 @@ import {} from '@univerjs/core';import { numfmt } from '@univerjs/base-numfmt-engine';import { Inject, Injector } from '@wendellhu/redi';-import { ACTION_NAMES as PLUGIN_ACTION_NAMES } from '../Enum';import { NumfmtPlugin } from '../../NumfmtPlugin';+import { INumfmtPluginData } from '../../Symbol';+import { NumfmtModel } from '../../Model';+import { ACTION_NAMES as PLUGIN_ACTION_NAMES } from '../Enum';-export class NumfmtActionExtension extends BaseActionExtension<NumfmtPlugin> {+export class NumfmtActionExtension extends BaseActionExtension {constructor(actionDataList: IActionData[],- _plugin: NumfmtPlugin,@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,+ @Inject(INumfmtPluginData) private _numfmtPluginData: NumfmtModel,@Inject(Injector) private readonly _sheetInjector: Injector,@Inject(CommandManager) private readonly _commandManager: CommandManager) {- super(actionDataList, _plugin);+ super(actionDataList);}override execute() {@@ -40,7 +42,7 @@ export class NumfmtActionExtension extends BaseActionExtension<NumfmtPlugin> {}const { cellValue, sheetId } = actionData;- const numfmtConfig = this._plugin.getNumfmtBySheetIdConfig(sheetId);+ const numfmtConfig = this._numfmtPluginData.getNumfmtBySheetIdConfig(sheetId);const currSheetNumfmtMatrix = new ObjectMatrix(numfmtConfig);const rangeMatrix = new ObjectMatrix(cellValue);@@ -72,7 +74,7 @@ export class NumfmtActionExtension extends BaseActionExtension<NumfmtPlugin> {}}-export class NumfmtActionExtensionFactory extends BaseActionExtensionFactory<NumfmtPlugin> {+export class NumfmtActionExtensionFactory extends BaseActionExtensionFactory {constructor(_plugin: NumfmtPlugin, @Inject(Injector) private readonly _sheetInjector: Injector) {super(_plugin);}@@ -81,7 +83,7 @@ export class NumfmtActionExtensionFactory extends BaseActionExtensionFactory<Numreturn 2;}- override create(actionDataList: ISheetActionData[]): BaseActionExtension<NumfmtPlugin> {- return this._sheetInjector.createInstance(NumfmtActionExtension, actionDataList, this._plugin);+ override create(actionDataList: ISheetActionData[]): BaseActionExtension {+ return this._sheetInjector.createInstance(NumfmtActionExtension, actionDataList);}}diff --git a/packages/sheets-plugin-numfmt/src/Basics/index.ts b/packages/sheets-plugin-numfmt/src/Basics/index.tsnew file mode 100644index 0000000000..81f3ba4e16--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Basics/index.ts@@ -0,0 +1,4 @@+export * from './Const';+export * from './Enum';+export * from './Register';+export * from './Observer';diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.tsindex cbb6698046..0a4c44cd5d 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts@@ -1,41 +1,28 @@-import {- ObjectMatrixPrimitiveType,- Command,- ObjectMatrix,- IRangeData,- Range,- ACTION_NAMES as CORE_ACTION_NAME,- CommandManager,- ICurrentUniverService-} from '@univerjs/core';+import { ObjectMatrixPrimitiveType, Command, ObjectMatrix, IRangeData, Range, ACTION_NAMES as CORE_ACTION_NAME, CommandManager, ICurrentUniverService } from '@univerjs/core';import { BaseComponentRender } from '@univerjs/base-ui';import { ISelectionManager, SelectionManager } from '@univerjs/base-sheets';import { IToolbarItemProps, SheetContainerUIController } from '@univerjs/ui-plugin-sheets';-import styles from '../View/UI/index.module.less';-import { NumfmtPlugin } from '../NumfmtPlugin';-import { DEFAULT_DATA, NUMFMT_PLUGIN_NAME, NumfmtConfig } from '../Basics/Const';-import { NumfmtModel } from '../Model/NumfmtModel';import { Inject, Injector } from '@wendellhu/redi';+import styles from '../View/UI/index.module.less';+import { DEFAULT_DATA, NUMFMT_PLUGIN_NAME, NumfmtConfig } from '../Basics';import { NumfmtModalController } from './NumfmtModalController';+import { INumfmtPluginData } from '../Symbol';+import { NumfmtModel } from '../Model';export class NumfmtController {protected _numfmtList: IToolbarItemProps;- protected _model: NumfmtModel;-protected _render: BaseComponentRender;- // eslint-disable-next-line max-lines-per-functionconstructor(- plugin: NumfmtPlugin,@Inject(ISelectionManager) private readonly _selectionManager: SelectionManager,@Inject(CommandManager) private readonly _commandManager: CommandManager,@Inject(SheetContainerUIController) private readonly _sheetContainerUIController: SheetContainerUIController,@Inject(Injector) private readonly _numfmtInjector: Injector,+ @Inject(INumfmtPluginData) private _numfmtPluginData: NumfmtModel,@Inject(ICurrentUniverService) private readonly _currentUniverService: ICurrentUniverService,@Inject(NumfmtModalController) private readonly _numfmtModalController: NumfmtModalController) {- this._model = new NumfmtModel();// const executeFormatter = (type: string): void => {// const manager = this._sheetPlugin.getSelectionManager();// const workbook = this._plugin.getContext().getWorkBook();@@ -181,7 +168,7 @@ export class NumfmtController {}getNumfmtBySheetIdConfig(sheetId: string): ObjectMatrixPrimitiveType<string> {- return this._model.getNumfmtBySheetIdConfig(sheetId);+ return this._numfmtPluginData.getNumfmtBySheetIdConfig(sheetId);}setNumfmtByRange(sheetId: string, numfmtRange: IRangeData, numfmtValue: string): void {diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.tsindex 139823ea8c..52a28095e3 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtModalController.ts@@ -1,12 +1,10 @@import { ComponentChildren, ComponentManager } from '@univerjs/base-ui';-import { SheetPlugin } from '@univerjs/base-sheets';import { LocaleService, ObserverManager } from '@univerjs/core';-import { SheetUIPlugin } from '@univerjs/ui-plugin-sheets';import { Inject } from '@wendellhu/redi';-import { NumfmtPlugin } from '../NumfmtPlugin';import { FormatContent } from '../View/UI/FormatContent';+import { NUMBERFORMAT, NUMFMT_PLUGIN_NAME, CURRENCYDETAIL, DATEFMTLISG } from '../Basics';import { NumfmtModal } from '../View/UI/NumfmtModal';-import { NUMBERFORMAT, NUMFMT_PLUGIN_NAME, CURRENCYDETAIL, DATEFMTLISG } from '../Basics/Const';+import { INumfmtPluginData } from '../Symbol';interface GroupProps {locale: string;@@ -30,17 +28,10 @@ export interface ModalDataProps {}export class NumfmtModalController {- protected _sheetUIPlugin: SheetUIPlugin;-- protected _sheetPlugin: SheetPlugin;-- protected _numfmtModal: NumfmtModal;-- protected _numfmtPlugin: NumfmtPlugin;-protected _modalData: ModalDataProps[];constructor(+ @Inject(INumfmtPluginData) private _numfmtPluginData: NumfmtModel,@Inject(ObserverManager) private readonly _observerManager: ObserverManager,@Inject(LocaleService) private readonly _localeService: LocaleService,@Inject(ComponentManager) private readonly _componentManager: ComponentManager@@ -152,7 +143,7 @@ export class NumfmtModalController {});}});- this._numfmtModal.setModal(this._modalData);+ this._numfmtPluginData.setModal(this._modalData);}showModal(name: string, show: boolean): void {diff --git a/packages/sheets-plugin-numfmt/src/Controller/index.ts b/packages/sheets-plugin-numfmt/src/Controller/index.tsnew file mode 100644index 0000000000..9f547ace01--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Controller/index.ts@@ -0,0 +1,2 @@+export * from './NumfmtController';+export * from './NumfmtModalController';diff --git a/packages/sheets-plugin-numfmt/src/Interfaces/INumfmtPluginConfig.ts b/packages/sheets-plugin-numfmt/src/Interfaces/INumfmtPluginConfig.tsnew file mode 100644index 0000000000..4e214eb71c--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Interfaces/INumfmtPluginConfig.ts@@ -0,0 +1 @@+export interface INumfmtPluginConfig {}diff --git a/packages/sheets-plugin-numfmt/src/Interfaces/index.ts b/packages/sheets-plugin-numfmt/src/Interfaces/index.tsnew file mode 100644index 0000000000..b609ffe24e--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Interfaces/index.ts@@ -0,0 +1 @@+export * from './INumfmtPluginConfig';diff --git a/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.ts b/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.tsindex 7458f9a182..36021458b3 100644--- a/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.ts+++ b/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.ts@@ -1,6 +1,6 @@import { SheetActionBase, ActionObservers, ISheetActionData, ObjectMatrixPrimitiveType, CommandUnit } from '@univerjs/core';-import { SetNumfmtRangeData } from '../Apply/SetNumfmtRangeData';-import { NumfmtController } from '../../Controller/NumfmtController';+import { SetNumfmtRangeData } from '../Apply';+import { NumfmtController } from '../../Controller';export interface ISetNumfmtRangeActionData extends ISheetActionData {numfmtMatrix: ObjectMatrixPrimitiveType<string>;diff --git a/packages/sheets-plugin-numfmt/src/Model/Action/index.ts b/packages/sheets-plugin-numfmt/src/Model/Action/index.tsnew file mode 100644index 0000000000..9559231122--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Model/Action/index.ts@@ -0,0 +1 @@+export * from './SetNumfmtRangeDataAction';diff --git a/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmtRangeData.ts b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmtRangeData.tsindex aa6dab87b2..5cc6dbdfde 100644--- a/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmtRangeData.ts+++ b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmtRangeData.ts@@ -1,5 +1,5 @@import { ObjectMatrix, ObjectMatrixPrimitiveType, Workbook } from '@univerjs/core';-import { NumfmtController } from '../../Controller/NumfmtController';+import { NumfmtController } from '../../Controller';export function SetNumfmtRangeData(workbook: Workbook,diff --git a/packages/sheets-plugin-numfmt/src/Model/Apply/index.ts b/packages/sheets-plugin-numfmt/src/Model/Apply/index.tsnew file mode 100644index 0000000000..c990c3ef98--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Model/Apply/index.ts@@ -0,0 +1 @@+export * from './SetNumfmtRangeData';diff --git a/packages/sheets-plugin-numfmt/src/Model/index.ts b/packages/sheets-plugin-numfmt/src/Model/index.tsnew file mode 100644index 0000000000..4e89b98eb2--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Model/index.ts@@ -0,0 +1,3 @@+export * from './Action';+export * from './Apply';+export * from './NumfmtModel';diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.tsindex ea4edb3902..2fe7335b42 100644--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts@@ -1,22 +1,23 @@-import { CommandManager, IRangeData, LocaleService, ObjectMatrixPrimitiveType, Plugin, PluginType, SheetContext } from '@univerjs/core';+import { CommandManager, IRangeData, LocaleService, ObjectMatrixPrimitiveType, Plugin, PluginType } from '@univerjs/core';import { Dependency, Inject, Injector } from '@wendellhu/redi';import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';-import { NUMFMT_PLUGIN_NAME } from './Basics/Const/PLUGIN_NAME';-import { install, NumfmtPluginObserve } from './Basics/Observer';+import { NUMFMT_PLUGIN_NAME, install, NumfmtPluginObserve, NumfmtActionExtensionFactory } from './Basics';+import { INumfmtPluginData } from './Symbol';+import { INumfmtPluginConfig } from './Interfaces';+import { NumfmtModalController, NumfmtController } from './Controller';+import { NumfmtModel } from './Model';+import en from './Locale/en';import zh from './Locale/zh';-import { NumfmtController } from './Controller/NumfmtController';-import { NumfmtActionExtensionFactory } from './Basics/Register/NumfmtActionExtension';-import { NumfmtModalController } from './Controller/NumfmtModalController';--export interface INumfmtPluginConfig {}-export class NumfmtPlugin extends Plugin<NumfmtPluginObserve, SheetContext> {+export class NumfmtPlugin extends Plugin<NumfmtPluginObserve> {static override type = PluginType.Sheet;+ private _numfmtModalController: NumfmtModalController;+private _numfmtController: NumfmtController;- private _numfmtModalController: NumfmtModalController;+ private _numfmtPluginData: NumfmtModel;private _numfmtActionExtensionFactory: NumfmtActionExtensionFactory;@@ -27,6 +28,10 @@ export class NumfmtPlugin extends Plugin<NumfmtPluginObserve, SheetContext> {@Inject(CommandManager) private readonly _commandManager: CommandManager) {super(NUMFMT_PLUGIN_NAME);++ this._numfmtPluginData = new NumfmtModel();+ this._injector.add([INumfmtPluginData, { useFactory: () => this._numfmtPluginData }]);+const sheetContainerUIController = this._injector.get(SheetContainerUIController);sheetContainerUIController.UIDidMount(() => {this.initializeDependencies(_injector);diff --git a/packages/sheets-plugin-numfmt/src/Model/RegisterAction.ts b/packages/sheets-plugin-numfmt/src/RegisterAction.tssimilarity index 52%rename from packages/sheets-plugin-numfmt/src/Model/RegisterAction.tsrename to packages/sheets-plugin-numfmt/src/RegisterAction.tsindex 7798b7877e..08927d1f5f 100644--- a/packages/sheets-plugin-numfmt/src/Model/RegisterAction.ts+++ b/packages/sheets-plugin-numfmt/src/RegisterAction.ts@@ -1,5 +1,5 @@import { CommandManager } from '@univerjs/core';-import { ACTION_NAMES } from '../Basics/Enum';-import { SetNumfmtRangeDataAction } from './Action/SetNumfmtRangeDataAction';+import { ACTION_NAMES } from './Basics/Enum';+import { SetNumfmtRangeDataAction } from './Model/Action/SetNumfmtRangeDataAction';CommandManager.register(ACTION_NAMES.SET_NUMFMT_RANGE_DATA_ACTION, SetNumfmtRangeDataAction);diff --git a/packages/sheets-plugin-numfmt/src/Symbol/index.ts b/packages/sheets-plugin-numfmt/src/Symbol/index.tsnew file mode 100644index 0000000000..109f04c336--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Symbol/index.ts@@ -0,0 +1,4 @@+import { createIdentifier } from '@wendellhu/redi';+import { NumfmtModel } from '../Model/NumfmtModel';++export const INumfmtPluginData = createIdentifier<NumfmtModel>('numfmt-plugin-data');diff --git a/packages/sheets-plugin-numfmt/src/index.ts b/packages/sheets-plugin-numfmt/src/index.tsindex e74a4c124e..a556adab7c 100644--- a/packages/sheets-plugin-numfmt/src/index.ts+++ b/packages/sheets-plugin-numfmt/src/index.ts@@ -1,3 +1,3 @@-import './Model/RegisterAction';+import './RegisterAction';export * from './NumfmtPlugin';