Skip to content

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.

xiugai

tonytonychopper1233fa6d67f0eeb
diff --git a/packages/base-sheets/src/Controller/RightMenuController.ts b/packages/base-sheets/src/Controller/RightMenuController.ts
index 8eed3dfafa..2c0c6209d8 100644
--- a/packages/base-sheets/src/Controller/RightMenuController.ts
+++ b/packages/base-sheets/src/Controller/RightMenuController.ts
@@ -1,438 +1,12 @@
-import { IMouseEvent, IPointerEvent } from '@univerjs/base-render';
-import { PLUGIN_NAMES, Tools } from '@univerjs/core';
-import { RightMenuModel, RightMenuProps } from '../Model/RightMenuModel';
import { SheetPlugin } from '../SheetPlugin';
-import { RightMenu } from '../View/UI/RightMenu';
import { SelectionControl } from './Selection/SelectionController';
import { SelectionModel } from '../Model/SelectionModel';
-import { RightMenuInput } from '../View/UI/RightMenu/RightMenuInput';
-import { RightMenuButton } from '../View/UI/RightMenu/RightMenuButton';
-import { RightMenuSelect } from '../View/UI/RightMenu/RightMenuSelect';
-import { RightMenuItem } from '../View/UI/RightMenu/RightMenuItem';
-import styles from '../View/UI/RightMenu/index.module.less';
-import { DefaultRightMenuConfig } from '../Basics';
-
-export interface IHideRightMenuConfig {
- hideInsertRow?: boolean;
- hideInsertColumn?: boolean;
- hideAddRowTop?: boolean;
- hideAddRowBottom?: boolean;
- hideAddColumnLeft?: boolean;
- hideAddColumnRight?: boolean;
- hideDeleteRow?: boolean;
- hideDeleteColumn?: boolean;
- hideHideRow?: boolean;
- hideShowRow?: boolean;
- hideRowHeight?: boolean;
- hideHideColumn?: boolean;
- hideShowColumn?: boolean;
- hideColumnWidth?: boolean;
- hideDeleteCell?: boolean;
- hideClearContent?: boolean;
- hideMatrix?: boolean;
-}
export class RightMenuController {
- private _rightMenuModel: RightMenuModel;
-
private _plugin: SheetPlugin;
- private _RightMenu: RightMenu;
-
- private _menuList: RightMenuProps[];
-
- constructor(plugin: SheetPlugin, config?: IHideRightMenuConfig) {
+ constructor(plugin: SheetPlugin) {
this._plugin = plugin;
-
- this._initRegisterComponent();
-
- const RightMenuConfig = config ? Tools.deepClone(DefaultRightMenuConfig) : Tools.deepMerge(DefaultRightMenuConfig, config);
-
- this._menuList = [
- {
- locale: ['rightClick.insert', 'rightClick.row'],
- onClick: this.insertRow,
- hide: RightMenuConfig.hideInsertRow,
- },
- {
- locale: ['rightClick.insert', 'rightClick.column'],
- onClick: this.insertColumn,
- hide: RightMenuConfig.hideInsertColumn,
- },
- {
- customLabel: {
- name: RightMenuInput.name,
- props: {
- prefixLocale: ['rightClick.to', 'rightClick.top', 'rightClick.add'],
- suffixLocale: 'rightClick.row',
- },
- },
- hide: RightMenuConfig.hideAddRowTop,
- },
- {
- customLabel: {
- name: RightMenuInput.name,
- props: {
- prefixLocale: ['rightClick.to', 'rightClick.bottom', 'rightClick.add'],
- suffixLocale: 'rightClick.row',
- },
- },
- hide: RightMenuConfig.hideAddRowBottom,
- },
- {
- customLabel: {
- name: RightMenuInput.name,
- props: {
- prefixLocale: ['rightClick.to', 'rightClick.left', 'rightClick.add'],
- suffixLocale: 'rightClick.column',
- },
- },
- hide: RightMenuConfig.hideAddColumnLeft,
- },
- {
- customLabel: {
- name: RightMenuInput.name,
- props: {
- prefixLocale: ['rightClick.to', 'rightClick.right', 'rightClick.add'],
- suffixLocale: 'rightClick.column',
- },
- },
- hide: RightMenuConfig.hideAddColumnRight,
- },
- {
- locale: ['rightClick.deleteSelected', 'rightClick.row'],
- onClick: this.deleteRow,
- hide: RightMenuConfig.hideDeleteRow,
- },
- {
- locale: ['rightClick.deleteSelected', 'rightClick.column'],
- onClick: this.deleteColumn,
- hide: RightMenuConfig.hideDeleteColumn,
- },
- {
- locale: ['rightClick.hideSelected', 'rightClick.row'],
- hide: RightMenuConfig.hideHideRow,
- },
- {
- locale: ['rightClick.showHide', 'rightClick.row'],
- hide: RightMenuConfig.hideShowRow,
- },
- {
- customLabel: {
- name: RightMenuInput.name,
- props: {
- prefixLocale: ['rightClick.row', 'rightClick.height'],
- suffix: 'px',
- onKeyUp: this.setRowHeight.bind(this),
- },
- },
- onClick: (...arg) => console.dir(arg),
- hide: RightMenuConfig.hideRowHeight,
- },
- {
- locale: ['rightClick.hideSelected', 'rightClick.column'],
- hide: RightMenuConfig.hideHideColumn,
- },
- {
- locale: ['rightClick.showHide', 'rightClick.column'],
- hide: RightMenuConfig.hideShowColumn,
- },
- {
- customLabel: {
- name: RightMenuInput.name,
- props: {
- prefixLocale: ['rightClick.column', 'rightClick.width'],
- suffix: 'px',
- onKeyUp: this.setColumnWidth.bind(this),
- },
- },
- hide: RightMenuConfig.hideColumnWidth,
- },
- {
- hide: RightMenuConfig.hideDeleteCell,
- customLabel: {
- name: RightMenuItem.name,
- props: {
- locale: 'rightClick.deleteCell',
- },
- },
- border: true,
- children: [
- {
- locale: ['rightClick.moveLeft'],
- className: styles.rightMenuCenter,
- onClick: (...arg: any) => this.deleteCellLeft(...arg),
- },
- {
- locale: ['rightClick.moveUp'],
- className: styles.rightMenuCenter,
- onClick: (...arg: any) => this.deleteCellTop(...arg),
- },
- ],
- },
- {
- locale: ['rightClick.clearContent'],
- onClick: (...arg: any) => this.clear(...arg),
- border: true,
- hide: RightMenuConfig.hideClearContent,
- },
- {
- hide: RightMenuConfig.hideMatrix,
- customLabel: {
- name: RightMenuItem.name,
- props: {
- locale: 'rightClick.matrix',
- },
- },
- children: [
- {
- customLabel: {
- name: RightMenuButton.name,
- props: {
- locale: 'rightClick.flip',
- children: [
- {
- locale: 'rightClick.upAndDown',
- },
- {
- locale: 'rightClick.leftAndRight',
- },
- ],
- },
- },
- },
- {
- customLabel: {
- name: RightMenuButton.name,
- props: {
- locale: 'rightClick.flip',
- children: [
- {
- locale: 'rightClick.clockwise',
- },
- {
- locale: 'rightClick.counterclockwise',
- },
- ],
- },
- },
- },
- {
- locale: ['rightClick.transpose'],
- },
- {
- customLabel: {
- name: RightMenuSelect.name,
- props: {
- locale: 'rightClick.matrixCalculation',
- options: [
- {
- locale: 'rightClick.plus',
- },
- {
- locale: 'rightClick.minus',
- },
- {
- locale: 'rightClick.multiply',
- },
- {
- locale: 'rightClick.divided',
- },
- {
- locale: 'rightClick.power',
- },
- {
- locale: 'rightClick.root',
- },
- {
- locale: 'rightClick.log',
- },
- ],
- },
- },
- },
- {
- customLabel: {
- name: RightMenuButton.name,
- props: {
- locale: 'rightClick.delete0',
- children: [
- {
- locale: 'rightClick.byRow',
- },
- {
- locale: 'rightClick.byCol',
- },
- ],
- },
- },
- },
- {
- customLabel: {
- name: RightMenuButton.name,
- props: {
- locale: 'rightClick.removeDuplicate',
- children: [
- {
- locale: 'rightClick.byRow',
- },
- {
- locale: 'rightClick.byCol',
- },
- ],
- },
- },
- },
- ],
- },
- // {
- // locale: ['rightClick.sortSelection'],
- // hide: true,
- // },
- // {
- // locale: ['rightClick.filterSelection'],
- // hide: true,
- // },
- // {
- // locale: ['rightClick.chartGeneration'],
- // hide: true,
- // },
- // {
- // locale: ['toolbar.insertImage'],
- // hide: true,
- // },
- // {
- // locale: ['toolbar.insertLink'],
- // hide: true,
- // },
- // {
- // locale: ['toolbar.dataValidation'],
- // hide: true,
- // },
- // {
- // locale: ['toolbar.cellFormat'],
- // hide: true,
- // },
- ];
-
- this._rightMenuModel = new RightMenuModel();
- this._initialize();
- }
-
- private _initialize() {
- const context = this._plugin.getContext();
- const manager = context.getObserverManager();
-
- manager.requiredObserver<RightMenu>('onRightMenuDidMountObservable', PLUGIN_NAMES.SPREADSHEET).add((component) => {
- this._RightMenu = component;
-
- this.resetMenuList(this.resetMenuLabel(this._menuList));
- });
-
- context.getContextObserver('onAfterChangeUILocaleObservable').add(() => {
- this.resetMenuList(this.resetMenuLabel(this._menuList));
- });
-
- context.getContextObserver('onSheetRenderDidMountObservable').add(() => {
- const spreadSheet = this._plugin.getSheetContainerControl().getContentRef().current;
- if (!spreadSheet) return;
- this._plugin.getMainComponent().onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;
- if (evt.button === 2) {
- spreadSheet.oncontextmenu = () => false;
-
- const selecionModel = this._plugin.getSelectionManager().getCurrentModel();
- console.log('selecionModel', selecionModel?.type);
-
- this._RightMenu.handleContextMenu(evt);
- }
- });
-
- // this._plugin.getRowComponent().onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- // const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;
- // if (evt.button === 2) {
- // spreadSheet.oncontextmenu = () => false;
- // this.resetMenuLabel(this._menuList, 'row');
- // this._RightMenu.handleContextMenu(evt);
- // }
- // });
- // this._plugin.getColumnComponent().onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- // const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;
- // if (evt.button === 2) {
- // spreadSheet.oncontextmenu = () => false;
- // this.resetMenuLabel(this._menuList, 'column');
- // this._RightMenu.handleContextMenu(evt);
- // }
- // });
- });
- }
-
- private _initRegisterComponent() {
- this._plugin.registerComponent(RightMenuInput.name, RightMenuInput);
- this._plugin.registerComponent(RightMenuButton.name, RightMenuButton);
- this._plugin.registerComponent(RightMenuSelect.name, RightMenuSelect);
- this._plugin.registerComponent(RightMenuItem.name, RightMenuItem);
- }
-
- resetLabel(label: string[] | string) {
- const locale = this._plugin.context.getLocale();
-
- let str = '';
-
- if (label instanceof Array) {
- label.forEach((item) => {
- if (item.includes('.')) {
- str += locale.get(item);
- } else {
- str += item;
- }
- });
- } else {
- if (label.includes('.')) {
- str = locale.get(label);
- } else {
- str += label;
- }
- }
-
- return str;
- }
-
- findLocale(obj: any) {
- for (let k in obj) {
- if (k === 'locale') {
- obj.label = this.resetLabel(obj[k]);
- } else if (k.endsWith('Locale')) {
- const index = k.indexOf('Locale');
- obj[k.slice(0, index)] = this.resetLabel(obj[k]);
- } else if (!obj[k].$$typeof) {
- if (Object.prototype.toString.call(obj[k]) === '[object Object]') {
- this.findLocale(obj[k]);
- } else if (Object.prototype.toString.call(obj[k]) === '[object Array]') {
- this.resetMenuLabel(obj[k]);
- }
- }
- }
-
- return obj;
- }
-
- resetMenuLabel(menuList: RightMenuProps[]) {
- for (let i = 0; i < menuList.length; i++) {
- let item = menuList[i];
-
- item = this.findLocale(item);
-
- if (item.children) {
- item.children = this.resetMenuLabel(item.children);
- }
- }
-
- return menuList;
- }
-
- resetMenuList(menuList: RightMenuProps[]) {
- this._RightMenu?.setMenuList(menuList);
}
private _getSelections() {
@@ -449,7 +23,7 @@ export class RightMenuController {
return selections;
}
- insertRow = (...arg: any) => {
+ insertRow = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
@@ -458,7 +32,7 @@ export class RightMenuController {
}
};
- deleteRow = (...arg: any) => {
+ deleteRow = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
@@ -466,7 +40,7 @@ export class RightMenuController {
}
};
- insertColumn = (...arg: any) => {
+ insertColumn = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
@@ -474,7 +48,7 @@ export class RightMenuController {
}
};
- deleteColumn = (...arg: any) => {
+ deleteColumn = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
@@ -482,7 +56,7 @@ export class RightMenuController {
}
};
- clear = (...arg: any) => {
+ clear = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
@@ -490,7 +64,7 @@ export class RightMenuController {
}
};
- deleteCellLeft = (...arg: any) => {
+ deleteCellLeft = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
@@ -498,7 +72,7 @@ export class RightMenuController {
}
};
- deleteCellTop = (...arg: any) => {
+ deleteCellTop = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
@@ -516,7 +90,6 @@ export class RightMenuController {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
sheet.setColumnWidth(selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1, Number(width));
}
- this._RightMenu.showRightMenu(false);
}
setRowHeight(e: Event) {
@@ -529,15 +102,5 @@ export class RightMenuController {
const sheet = this._plugin.getContext().getWorkBook().getActiveSheet();
sheet.setRowHeights(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1, Number(height));
}
- this._RightMenu.showRightMenu(false);
}
-
- addItem = (item: RightMenuProps[] | RightMenuProps) => {
- if (item instanceof Array) {
- this._menuList.push(...item);
- } else {
- this._menuList.push(item);
- }
- this.resetMenuList(this.resetMenuLabel(this._menuList));
- };
}
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
index dfd65b41d3..7e4c08f5ee 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
@@ -641,21 +641,21 @@ export class SelectionManager {
private _rowEventInitial() {
const row = this._rowComponent;
row.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._rowTitleControl.highlightRowTitle(evt);
+ // this._rowTitleControl.highlightRowTitle(evt);
});
}
private _columnEventInitial() {
const column = this._columnComponent;
column.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._columnTitleControl.highlightColumnTitle(evt);
+ // this._columnTitleControl.highlightColumnTitle(evt);
});
}
private _leftTopEventInitial() {
const leftTop = this._leftTopComponent;
leftTop.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- console.log('leftTop_moveObserver', evt);
+ // console.log('leftTop_moveObserver', evt);
});
}
@@ -678,25 +678,25 @@ export class SelectionManager {
const cellInfo = cell
? {
- row: cell.row,
- column: cell.column,
- isMerged: false,
- isMergedMainCell: false,
- startY: 0,
- endY: 0,
- startX: 0,
- endX: 0,
- mergeInfo: {
- startColumn,
- startRow,
- endColumn,
- endRow,
- startY: 0,
- endY: 0,
- startX: 0,
- endX: 0,
- },
- }
+ row: cell.row,
+ column: cell.column,
+ isMerged: false,
+ isMergedMainCell: false,
+ startY: 0,
+ endY: 0,
+ startX: 0,
+ endX: 0,
+ mergeInfo: {
+ startColumn,
+ startRow,
+ endColumn,
+ endRow,
+ startY: 0,
+ endY: 0,
+ startX: 0,
+ endX: 0,
+ },
+ }
: null;
// Only update data, not render
diff --git a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
index 1b6243524a..84435388f6 100644
--- a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
@@ -1,10 +1,11 @@
import { IMouseEvent, IPointerEvent } from '@univerjs/base-render';
import { SheetPlugin } from '@univerjs/base-sheets';
import { BaseMenuItem, BaseSelectChildrenProps, resetDataLabel } from '@univerjs/base-ui';
-import { PLUGIN_NAMES, Tools } from '@univerjs/core';
+import { PLUGIN_NAMES, Tools, UIObserver } from '@univerjs/core';
import { SheetUIPlugin } from '..';
-import { DefaultRightMenuConfig, SheetRightMenuConfig } from '../Basics';
-import { RightMenu } from '../View';
+import { DefaultRightMenuConfig, SheetRightMenuConfig, SHEET_UI_PLUGIN_NAME } from '../Basics';
+import { RightMenu, RightMenuInput, RightMenuItem } from '../View';
+import styles from '../View/RightMenu/index.module.less'
export interface CustomLabelOptions extends BaseSelectChildrenProps {
locale?: string;
@@ -53,16 +54,250 @@ export class RightMenuUIController {
this._menuList = [
{
- locale: 'rightClick.insertRow',
- onClick: () => { },
+ label: 'rightClick.insertRow',
+ onClick: this.insertRow,
show: this._config.InsertRow,
},
+ {
+ label: 'rightClick.insertColumn',
+ onClick: this.insertColumn,
+ show: this._config.InsertColumn,
+ },
+ {
+ customLabel: {
+ name: RightMenuInput.name,
+ props: {
+ prefix: 'rightClick.toTopAdd',
+ suffix: 'rightClick.row',
+ }
+ },
+ show: this._config.AddRowTop,
+ },
+ {
+ customLabel: {
+ name: RightMenuInput.name,
+ props: {
+ prefix: 'rightClick.toBottomAdd',
+ suffix: 'rightClick.row',
+ },
+ },
+ show: this._config.AddRowBottom,
+ },
+ {
+ customLabel: {
+ name: RightMenuInput.name,
+ props: {
+ prefix: 'rightClick.toLeftAdd',
+ suffix: 'rightClick.column',
+ },
+ },
+ show: this._config.AddColumnLeft,
+ },
+ {
+ customLabel: {
+ name: RightMenuInput.name,
+ props: {
+ prefix: 'rightClick.toRightAdd',
+ suffix: 'rightClick.column',
+ },
+ },
+ show: this._config.AddColumnRight,
+ },
+ {
+ label: 'rightClick.deleteSelectedRow',
+ onClick: this.deleteRow,
+ show: this._config.DeleteRow,
+ },
+ {
+ label: 'rightClick.deleteSelectedColumn',
+ onClick: this.deleteColumn,
+ show: this._config.DeleteColumn,
+ },
+ {
+ label: 'rightClick.hideSelectedRow',
+ show: this._config.HideRow,
+ },
+ {
+ label: 'rightClick.showHideRow',
+ show: this._config.ShowRow,
+ },
+ {
+ customLabel: {
+ name: RightMenuInput.name,
+ props: {
+ prefix: 'rightClick.rowHeight',
+ suffix: 'px',
+ onKeyUp: this.setRowHeight.bind(this),
+ },
+ },
+ onClick: () => { },
+ show: this._config.RowHeight,
+ },
+ {
+ label: 'rightClick.hideSelectedColumn',
+ show: this._config.HideColumn,
+ },
+ {
+ label: 'rightClick.showHideColumn',
+ show: this._config.ShowColumn,
+ },
+ {
+ customLabel: {
+ name: RightMenuInput.name,
+ props: {
+ prefix: 'rightClick.columnWidth',
+ suffix: 'px',
+ onKeyUp: this.setColumnWidth.bind(this),
+ },
+ },
+ show: this._config.ColumnWidth,
+ },
+ {
+ show: this._config.DeleteCell,
+ customLabel: {
+ name: RightMenuItem.name,
+ props: {
+ label: 'rightClick.deleteCell',
+ },
+ },
+ border: true,
+ children: [
+ {
+ label: 'rightClick.moveLeft',
+ className: styles.rightMenuCenter,
+ onClick: this.deleteCellLeft,
+ },
+ {
+ label: 'rightClick.moveUp',
+ className: styles.rightMenuCenter,
+ onClick: this.deleteCellTop,
+ },
+ ],
+ },
+ {
+ label: 'rightClick.clearContent',
+ onClick: this.clearContent,
+ border: true,
+ show: this._config.ClearContent,
+ },
+ // {
+ // show: this._config.hideMatrix,
+ // customLabel: {
+ // name: RightMenuItem.name,
+ // props: {
+ // locale: 'rightClick.matrix',
+ // },
+ // },
+ // children: [
+ // {
+ // customLabel: {
+ // name: RightMenuButton.name,
+ // props: {
+ // locale: 'rightClick.flip',
+ // children: [
+ // {
+ // locale: 'rightClick.upAndDown',
+ // },
+ // {
+ // locale: 'rightClick.leftAndRight',
+ // },
+ // ],
+ // },
+ // },
+ // },
+ // {
+ // customLabel: {
+ // name: RightMenuButton.name,
+ // props: {
+ // locale: 'rightClick.flip',
+ // children: [
+ // {
+ // locale: 'rightClick.clockwise',
+ // },
+ // {
+ // locale: 'rightClick.counterclockwise',
+ // },
+ // ],
+ // },
+ // },
+ // },
+ // {
+ // locale: ['rightClick.transpose'],
+ // },
+ // {
+ // customLabel: {
+ // name: RightMenuSelect.name,
+ // props: {
+ // locale: 'rightClick.matrixCalculation',
+ // options: [
+ // {
+ // locale: 'rightClick.plus',
+ // },
+ // {
+ // locale: 'rightClick.minus',
+ // },
+ // {
+ // locale: 'rightClick.multiply',
+ // },
+ // {
+ // locale: 'rightClick.divided',
+ // },
+ // {
+ // locale: 'rightClick.power',
+ // },
+ // {
+ // locale: 'rightClick.root',
+ // },
+ // {
+ // locale: 'rightClick.log',
+ // },
+ // ],
+ // },
+ // },
+ // },
+ // {
+ // customLabel: {
+ // name: RightMenuButton.name,
+ // props: {
+ // locale: 'rightClick.delete0',
+ // children: [
+ // {
+ // locale: 'rightClick.byRow',
+ // },
+ // {
+ // locale: 'rightClick.byCol',
+ // },
+ // ],
+ // },
+ // },
+ // },
+ // {
+ // customLabel: {
+ // name: RightMenuButton.name,
+ // props: {
+ // locale: 'rightClick.removeDuplicate',
+ // children: [
+ // {
+ // locale: 'rightClick.byRow',
+ // },
+ // {
+ // locale: 'rightClick.byCol',
+ // },
+ // ],
+ // },
+ // },
+ // },
+ // ],
+ // },
];
this._initialize();
}
private _initialize() {
+ this._plugin.getComponentManager().register(RightMenuInput.name, RightMenuInput)
+ this._plugin.getComponentManager().register(RightMenuItem.name, RightMenuItem)
+
this._sheetPlugin.getMainComponent().onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
if (evt.button === 2) {
this._rightMenu.handleContextMenu(evt);
@@ -82,4 +317,67 @@ export class RightMenuUIController {
const menuList = resetDataLabel(this._menuList, locale);
this._rightMenu?.setMenuList(menuList);
}
+
+ setUIObserve<T>(msg: UIObserver<T>) {
+ this._plugin.getContext().getObserverManager().requiredObserver<UIObserver<T>>('onUIChangeObservable', 'core').notifyObservers(msg);
+ }
+
+ insertRow() {
+ const msg = {
+ name: 'insertRow',
+ };
+ this.setUIObserve(msg);
+ }
+
+ insertColumn() {
+ const msg = {
+ name: 'insertColumn',
+ };
+ this.setUIObserve(msg);
+ }
+
+ deleteRow() {
+ const msg = {
+ name: 'deleteRow',
+ };
+ this.setUIObserve(msg);
+ }
+
+ deleteColumn() {
+ const msg = {
+ name: 'deleteColumn',
+ };
+ this.setUIObserve(msg);
+ }
+
+ setRowHeight(e: Event) {
+ if ((e as KeyboardEvent).key !== 'Enter') {
+ return;
+ }
+ const height = (e.target as HTMLInputElement).value;
+ const msg = {
+ name: 'setRowHeight',
+ value: height
+ };
+ this.setUIObserve(msg);
+ }
+
+ setColumnWidth(e: Event) {
+ if ((e as KeyboardEvent).key !== 'Enter') {
+ return;
+ }
+ const width = (e.target as HTMLInputElement).value;
+ const msg = {
+ name: 'setColumnWidth',
+ value: width
+ };
+ this.setUIObserve(msg);
+ }
+
+ deleteCellLeft() {
+ }
+
+ deleteCellTop() { }
+
+ clearContent() { }
}
diff --git a/packages/ui-plugin-sheets/src/Locale/en.ts b/packages/ui-plugin-sheets/src/Locale/en.ts
index 82687eea40..8b5d1e9acc 100644
--- a/packages/ui-plugin-sheets/src/Locale/en.ts
+++ b/packages/ui-plugin-sheets/src/Locale/en.ts
@@ -433,6 +433,18 @@ export default {
hide: 'Hide',
hideSelected: 'Hide selected ',
showHide: 'Show hidden ',
+ toTopAdd: 'Towards Top Add',
+ toBottomAdd: 'Towards Bottom Add',
+ toLeftAdd: 'Towards Left Add',
+ toRightAdd: 'Towards Right Add',
+ deleteSelectedRow: 'Delete selected row',
+ deleteSelectedColumn: 'Delete selected column',
+ hideSelectedRow: 'Hide selected row',
+ showHideRow: 'Show selected row',
+ rowHeight: 'Row height',
+ hideSelectedColumn: 'Hide selected column',
+ showHideColumn: 'Show hide column',
+ columnWidth: 'Column width',
to: 'Towards',
left: 'Left',
right: 'Right',
diff --git a/packages/ui-plugin-sheets/src/Locale/zh.ts b/packages/ui-plugin-sheets/src/Locale/zh.ts
index 85236ecfaf..d9e3a8b42e 100644
--- a/packages/ui-plugin-sheets/src/Locale/zh.ts
+++ b/packages/ui-plugin-sheets/src/Locale/zh.ts
@@ -296,6 +296,18 @@ export default {
hide: '隐藏',
hideSelected: '隐藏选中',
showHide: '显示隐藏',
+ toTopAdd: '向上增加',
+ toBottomAdd: '向下增加',
+ toLeftAdd: '向左增加',
+ toRightAdd: '向右增加',
+ deleteSelectedRow: '删除选中行',
+ deleteSelectedColumn: '删除选中列',
+ hideSelectedRow: '隐藏选中行',
+ showHideRow: '显示隐藏行',
+ rowHeight: '行高',
+ hideSelectedColumn: '隐藏选中列',
+ showHideColumn: '显示隐藏列',
+ columnWidth: '列宽',
to: '向',
left: '左',
right: '右',
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
index 6af61a5856..d0fd4a4229 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
@@ -10,6 +10,7 @@ interface IState {
srcElement: any;
eventType: string | null;
children: RightMenuProps[];
+ replace: RightMenuProps[];
}
export class RightMenu extends Component<BaseRightMenuProps, IState> {
@@ -21,13 +22,14 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
srcElement: null,
eventType: null,
children: [],
+ replace: [],
};
}
root = createRef();
// 转换成渲染需要的数据
- resetMenuList(children: RightMenuProps[]) {
+ resetMenuList(children: RightMenuProps[], replace: RightMenuProps[]) {
const componentManager = this.getContext().getPluginManager().getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)?.getComponentManager();
for (let i = 0; i < children.length; i++) {
@@ -39,12 +41,12 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
if (Label) {
item.label = <Label {...props} />;
}
- } else {
- item.label = this.getLocale(item.locale);
+ } else if (typeof item.label === 'string') {
+ item.label = this.getLocale(replace[i].label as string);
}
if (item.children) {
- item.children = this.resetMenuList(item.children);
+ item.children = this.resetMenuList(item.children, replace[i].children!);
}
}
@@ -53,7 +55,8 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
setMenuList(children: RightMenuProps[]) {
this.setState({
- children: this.resetMenuList(children),
+ children,
+ replace: JSON.parse(JSON.stringify(children)),
});
}
@@ -155,7 +158,7 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
e.preventDefault();
}}
>
- <Menu ref={this.ulRef} menu={this.resetMenuList(this.state.children)} onClick={this.handleClick}></Menu>
+ <Menu ref={this.ulRef} menu={this.resetMenuList(this.state.children, this.state.replace)} onClick={this.handleClick}></Menu>
</div>
)
);
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
index 4008028ddd..93328b60eb 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
@@ -1,7 +1,7 @@
import { Component, Input } from '@univerjs/base-ui';
interface IProps {
- prefix: string[];
+ prefix: string;
suffix: string;
onKeyUp?: (e: Event) => void;
}
@@ -18,12 +18,11 @@ export class RightMenuInput extends Component<IProps> {
render() {
const { prefix, suffix } = this.props;
-
return (
<div>
- {prefix}
+ {this.getLocale(prefix)}
<Input onKeyUp={this.handleKeyUp.bind(this)} type="number" placeholder="1" onClick={this.handleClick}></Input>
- {suffix}
+ {this.getLocale(suffix)}
</div>
);
}
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
index 3bb39b7ad9..675a7848bd 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
@@ -11,7 +11,7 @@ export class RightMenuItem extends Component<IProps> {
return (
<div className={styles.rightMenuItem}>
- {label}
+ {this.getLocale(label)}
<Icon.Format.RightIcon />
</div>
);