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.

refactor(*): refactor toolbar UI & context menus (#86)

Wenzhao Hu147b2115c455
diff --git a/packages/base-docs/package.json b/packages/base-docs/package.json
index 71e273207d..459a9847c3 100644
--- a/packages/base-docs/package.json
+++ b/packages/base-docs/package.json
@@ -57,7 +57,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1"
}
diff --git a/packages/base-formula-engine/package.json b/packages/base-formula-engine/package.json
index 79feb0bc82..0e34128a5a 100644
--- a/packages/base-formula-engine/package.json
+++ b/packages/base-formula-engine/package.json
@@ -49,7 +49,7 @@
},
"dependencies": {
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"preact": "^10.12.1"
}
}
\ No newline at end of file
diff --git a/packages/base-render/package.json b/packages/base-render/package.json
index a5a28e8371..77cc11f6aa 100644
--- a/packages/base-render/package.json
+++ b/packages/base-render/package.json
@@ -56,6 +56,6 @@
},
"dependencies": {
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6"
+ "@wendellhu/redi": "^0.12.7"
}
}
\ No newline at end of file
diff --git a/packages/base-render/src/RenderEngine.ts b/packages/base-render/src/RenderEngine.ts
index 0b2fec41fa..7eacb9c2d2 100644
--- a/packages/base-render/src/RenderEngine.ts
+++ b/packages/base-render/src/RenderEngine.ts
@@ -10,7 +10,7 @@ export class RenderEngine extends Plugin {
private _engine: Engine;
- constructor(@Optional(Injector) override readonly _injector: Injector) {
+ constructor(_config: undefined, @Optional(Injector) override readonly _injector: Injector) {
super(PLUGIN_NAMES.BASE_RENDER);
this._engine = new Engine();
@@ -21,4 +21,4 @@ export class RenderEngine extends Plugin {
getEngine(): Engine {
return this._engine;
}
-}
+}
\ No newline at end of file
diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.json
index c446910297..3416ddcc7e 100644
--- a/packages/base-sheets/package.json
+++ b/packages/base-sheets/package.json
@@ -58,6 +58,7 @@
"dependencies": {
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6"
+ "@wendellhu/redi": "^0.12.7",
+ "rxjs": "^7.8.1"
}
}
\ No newline at end of file
diff --git a/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts b/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts
index 35f801147c..c05d265b6c 100644
--- a/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts
+++ b/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts
@@ -16,7 +16,6 @@ export const ClearSelectionContentCommand: ICommand = {
const selectionManager = accessor.get(ISelectionManager);
const undoRedoService = accessor.get(IUndoRedoService);
- // TODO: this is to verbose to get a serializable range, a range should have worksheet id as well
const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
const worksheet = workbook.getActiveSheet();
const selections = selectionManager.getCurrentSelections();
diff --git a/packages/base-sheets/src/Commands/Commands/delete-range-move-top.command.ts b/packages/base-sheets/src/Commands/Commands/delete-range-move-up.command.ts
similarity index 93%
rename from packages/base-sheets/src/Commands/Commands/delete-range-move-top.command.ts
rename to packages/base-sheets/src/Commands/Commands/delete-range-move-up.command.ts
index 2ec3b47bb6..09d2095997 100644
--- a/packages/base-sheets/src/Commands/Commands/delete-range-move-top.command.ts
+++ b/packages/base-sheets/src/Commands/Commands/delete-range-move-up.command.ts
@@ -5,7 +5,7 @@ import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../Mutation
import { InsertRangeMutation } from '../Mutations/insert-range.mutation';
import { IDeleteRangeMutationParams, IInsertRangeMutationParams } from '../../Basics/Interfaces/MutationInterface';
-export interface IDeleteRangeMoveTopParams {
+export interface IDeleteRangeMoveUpParams {
workbookId: string;
worksheetId: string;
range: IRangeData;
@@ -14,11 +14,11 @@ export interface IDeleteRangeMoveTopParams {
/**
* The command to delete range.
*/
-export const DeleteRangeMoveTopCommand: ICommand = {
+export const DeleteRangeMoveUpCommand: ICommand = {
type: CommandType.COMMAND,
- id: 'sheet.command.delete-range-move-top',
+ id: 'sheet.command.delete-range-move-up',
- handler: async (accessor: IAccessor, params: IDeleteRangeMoveTopParams) => {
+ handler: async (accessor: IAccessor, params: IDeleteRangeMoveUpParams) => {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const { range, workbookId, worksheetId } = params;
diff --git a/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts b/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts
index 39c48cd696..ce4402f1f0 100644
--- a/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts
+++ b/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts
@@ -106,7 +106,7 @@ export const InsertColCommand: ICommand<InsertColCommandParams> = {
};
}
const undoMutationParams: IRemoveColMutationParams = InsertColMutationFactory(accessor, redoMutationParams);
- const result = commandService.executeCommand(InsertRowMutation.id, redoMutationParams);
+ const result = commandService.executeCommand(InsertColMutation.id, redoMutationParams);
if (result) {
undoRedoService.pushUndoRedo({
URI: 'sheet',
diff --git a/packages/base-sheets/src/Commands/Commands/set-border-command.ts b/packages/base-sheets/src/Commands/Commands/set-border-command.ts
index 2c542375ee..88e66047d8 100644
--- a/packages/base-sheets/src/Commands/Commands/set-border-command.ts
+++ b/packages/base-sheets/src/Commands/Commands/set-border-command.ts
@@ -1,9 +1,11 @@
import {
BorderStyleTypes,
+ BorderType,
CommandType,
IBorderStyleData,
ICommand,
ICommandService,
+ ICurrentUniverService,
IRangeData,
IStyleData,
IUndoRedoService,
@@ -14,6 +16,84 @@ import {
import { IAccessor } from '@wendellhu/redi';
import { ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../Mutations/set-range-values.mutation';
+import { BorderStyleManagerService } from '../../Services/border-style-manager.service';
+import { ISelectionManager } from '../../Services/tokens';
+
+function forEach(rangeData: IRangeData, action: (row: number, column: number) => void): void {
+ const { startRow, startColumn, endRow, endColumn } = rangeData;
+ for (let i = startRow; i <= endRow; i++) {
+ for (let j = startColumn; j <= endColumn; j++) {
+ action(i, j);
+ }
+ }
+}
+
+export interface ISetBorderPositionCommandParams {
+ value: BorderType;
+}
+
+export const SetBorderPositionCommand: ICommand<ISetBorderPositionCommandParams> = {
+ id: 'sheet.command.set-border-position',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor, params: ISetBorderPositionCommandParams) => {
+ const commandService = accessor.get(ICommandService);
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const selectionManager = accessor.get(ISelectionManager);
+ const borderStyleManagerService = accessor.get(BorderStyleManagerService);
+
+ const selections = selectionManager.getCurrentSelections();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ if (!selections.length) {
+ return false;
+ }
+
+ const value = params.value;
+ const borderInfo = borderStyleManagerService.getBorderInfo();
+ const destParams: ISetBorderCommandParams = {
+ workbookId: workbook.getUnitId(),
+ worksheetId: workbook.getActiveSheet().getSheetId(),
+ range: selections[0],
+ top: value === BorderType.TOP || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.HORIZONTAL,
+ left: value === BorderType.LEFT || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.VERTICAL,
+ bottom: value === BorderType.BOTTOM || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.HORIZONTAL,
+ right: value === BorderType.RIGHT || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.VERTICAL,
+ vertical: value === BorderType.VERTICAL || value === BorderType.ALL || value === BorderType.INSIDE,
+ horizontal: value === BorderType.HORIZONTAL || value === BorderType.ALL || value === BorderType.INSIDE,
+ style: borderInfo.style,
+ color: borderInfo.color,
+ };
+
+ return commandService.executeCommand(SetBorderCommand.id, destParams);
+ },
+};
+
+export interface ISetBorderStyleCommandParams {
+ value: BorderStyleTypes;
+}
+
+export const SetBorderStyleCommand: ICommand = {
+ id: 'sheet.command.set-border-style',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor, params: ISetBorderStyleCommandParams) => {
+ const borderManager = accessor.get(BorderStyleManagerService);
+ borderManager.setStyle(params.value);
+ return true;
+ },
+};
+
+export interface ISetBorderColorCommandParams {
+ value: string;
+}
+
+export const SetBorderColorCommand: ICommand<ISetBorderColorCommandParams> = {
+ id: 'sheet.command.set-border-color',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor, params: ISetBorderColorCommandParams) => {
+ const borderManager = accessor.get(BorderStyleManagerService);
+ borderManager.setColor(params.value);
+ return true;
+ },
+};
export interface ISetBorderCommandParams {
workbookId: string;
@@ -29,19 +109,10 @@ export interface ISetBorderCommandParams {
style?: BorderStyleTypes;
}
-function forEach(rangeData: IRangeData, action: (row: number, column: number) => void): void {
- const { startRow, startColumn, endRow, endColumn } = rangeData;
- for (let i = startRow; i <= endRow; i++) {
- for (let j = startColumn; j <= endColumn; j++) {
- action(i, j);
- }
- }
-}
-
/**
* The command to clear content in current selected ranges.
*/
-export const SetBorderCommand: ICommand = {
+export const SetBorderCommand: ICommand<ISetBorderCommandParams> = {
id: 'sheet.command.set-border',
type: CommandType.COMMAND,
// eslint-disable-next-line max-lines-per-function
@@ -288,7 +359,8 @@ export const SetBorderCommand: ICommand = {
const clearMutationParams: ISetRangeValuesMutationParams = {
rangeData: range,
- worksheetId: worksheet.getSheetId(),
+ worksheetId,
+ workbookId,
};
const undoClearMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, clearMutationParams);
diff --git a/packages/base-sheets/src/Commands/Commands/set-style.command.ts b/packages/base-sheets/src/Commands/Commands/set-style.command.ts
index 74383b69c0..70fd963600 100644
--- a/packages/base-sheets/src/Commands/Commands/set-style.command.ts
+++ b/packages/base-sheets/src/Commands/Commands/set-style.command.ts
@@ -5,7 +5,6 @@ import {
FontItalic,
FontWeight,
HorizontalAlign,
- IBorderData,
IColorStyle,
ICommand,
ICommandService,
@@ -115,10 +114,10 @@ export const SetStyleCommand: ICommand<ISetStyleParams> = {
* Set bold font style to currently selected ranges. If the cell is already bold then it will cancel the bold style.
*/
export const SetBoldCommand: ICommand = {
- // TODO@wzhudev: toggle bold command?
+ // TODO@wzhudev: name to toggle bold command?
type: CommandType.COMMAND,
id: 'sheet.command.set-bold',
- handler: async (accessor, params) => {
+ handler: async (accessor) => {
const commandService = accessor.get(ICommandService);
const selectionManager = accessor.get(ISelectionManager);
const currentlyBold = selectionManager.getCurrentCell()?.getFontWeight() === FontWeight.BOLD;
@@ -203,7 +202,7 @@ export const SetStrikeThroughCommand: ICommand = {
};
export interface ISetFontFamilyCommandParams {
- fontFamily: string;
+ value: string;
}
export const SetFontFamilyCommand: ICommand<ISetFontFamilyCommandParams> = {
@@ -218,7 +217,7 @@ export const SetFontFamilyCommand: ICommand<ISetFontFamilyCommandParams> = {
const setStyleParams: ISetStyleParams<string> = {
style: {
type: 'ff',
- value: params.fontFamily,
+ value: params.value,
},
};
@@ -229,12 +228,12 @@ export const SetFontFamilyCommand: ICommand<ISetFontFamilyCommandParams> = {
};
export interface ISetFontSizeCommandParams {
- fontSize: number;
+ value: number;
}
export const SetFontSizeCommand: ICommand<ISetFontSizeCommandParams> = {
type: CommandType.COMMAND,
- id: 'sheet.command.set-font-family',
+ id: 'sheet.command.set-font-size',
handler: async (accessor, params) => {
if (!params) {
return false;
@@ -244,7 +243,7 @@ export const SetFontSizeCommand: ICommand<ISetFontSizeCommandParams> = {
const setStyleParams: ISetStyleParams<number> = {
style: {
type: 'fs',
- value: params.fontSize,
+ value: params.value,
},
};
@@ -253,12 +252,12 @@ export const SetFontSizeCommand: ICommand<ISetFontSizeCommandParams> = {
};
export interface ISetColorCommandParams {
- color: IColorStyle;
+ value: string;
}
export const SetTextColorCommand: ICommand<ISetColorCommandParams> = {
type: CommandType.COMMAND,
- id: 'sheet.command.set-font-family',
+ id: 'sheet.command.set-text-color',
handler: async (accessor, params) => {
if (!params) {
return false;
@@ -268,7 +267,27 @@ export const SetTextColorCommand: ICommand<ISetColorCommandParams> = {
const setStyleParams: ISetStyleParams<IColorStyle> = {
style: {
type: 'cl',
- value: params.color,
+ value: {
+ rgb: params.value,
+ },
+ },
+ };
+
+ return commandService.executeCommand(SetStyleCommand.id, setStyleParams);
+ },
+};
+
+export const ResetTextColorCommand: ICommand = {
+ type: CommandType.COMMAND,
+ id: 'sheet.command.reset-text-color',
+ handler: async (accessor) => {
+ const commandService = accessor.get(ICommandService);
+ const setStyleParams: ISetStyleParams<IColorStyle> = {
+ style: {
+ type: 'cl',
+ value: {
+ rgb: '#000',
+ },
},
};
@@ -288,7 +307,9 @@ export const SetBackgroundColorCommand: ICommand<ISetColorCommandParams> = {
const setStyleParams: ISetStyleParams<IColorStyle> = {
style: {
type: 'bg',
- value: params.color,
+ value: {
+ rgb: params.value,
+ },
},
};
@@ -296,23 +317,17 @@ export const SetBackgroundColorCommand: ICommand<ISetColorCommandParams> = {
},
};
-export interface ISetCellBorderCommandParams {
- border: IBorderData;
-}
-
-export const SetCellBorderCommand: ICommand<ISetCellBorderCommandParams> = {
+export const ResetBackgroundColorCommand: ICommand = {
type: CommandType.COMMAND,
- id: 'sheet.command.set-cell-border',
- handler: async (accessor, params) => {
- if (!params) {
- return false;
- }
-
+ id: 'sheet.command.reset-background-color',
+ handler: async (accessor) => {
const commandService = accessor.get(ICommandService);
- const setStyleParams: ISetStyleParams<IBorderData> = {
+ const setStyleParams: ISetStyleParams<IColorStyle> = {
style: {
- type: 'bd',
- value: params.border,
+ type: 'bg',
+ value: {
+ rgb: undefined,
+ },
},
};
@@ -321,7 +336,7 @@ export const SetCellBorderCommand: ICommand<ISetCellBorderCommandParams> = {
};
export interface ISetVerticalTextAlignCommandParams {
- align: VerticalAlign;
+ value: VerticalAlign;
}
export const SetVerticalTextAlignCommand: ICommand<ISetVerticalTextAlignCommandParams> = {
@@ -336,7 +351,7 @@ export const SetVerticalTextAlignCommand: ICommand<ISetVerticalTextAlignCommandP
const setStyleParams: ISetStyleParams<VerticalAlign> = {
style: {
type: 'vt',
- value: params.align,
+ value: params.value,
},
};
@@ -345,7 +360,7 @@ export const SetVerticalTextAlignCommand: ICommand<ISetVerticalTextAlignCommandP
};
export interface ISetHorizontalTextAlignCommandParams {
- align: HorizontalAlign;
+ value: HorizontalAlign;
}
export const SetHorizontalTextAlignCommand: ICommand<ISetHorizontalTextAlignCommandParams> = {
@@ -360,7 +375,7 @@ export const SetHorizontalTextAlignCommand: ICommand<ISetHorizontalTextAlignComm
const setStyleParams: ISetStyleParams<HorizontalAlign> = {
style: {
type: 'ht',
- value: params.align,
+ value: params.value,
},
};
@@ -369,7 +384,7 @@ export const SetHorizontalTextAlignCommand: ICommand<ISetHorizontalTextAlignComm
};
export interface ISetTextWrapCommandParams {
- wrap: WrapStrategy;
+ value: WrapStrategy;
}
export const SetTextWrapCommand: ICommand<ISetTextWrapCommandParams> = {
@@ -384,7 +399,7 @@ export const SetTextWrapCommand: ICommand<ISetTextWrapCommandParams> = {
const setStyleParams: ISetStyleParams<WrapStrategy> = {
style: {
type: 'tb',
- value: params.wrap,
+ value: params.value,
},
};
@@ -393,7 +408,7 @@ export const SetTextWrapCommand: ICommand<ISetTextWrapCommandParams> = {
};
export interface ISetTextRotationCommandParams {
- rotation: ITextRotation;
+ value: number | string;
}
export const SetTextRotationCommand: ICommand<ISetTextRotationCommandParams> = {
@@ -408,7 +423,9 @@ export const SetTextRotationCommand: ICommand<ISetTextRotationCommandParams> = {
const setStyleParams: ISetStyleParams<ITextRotation> = {
style: {
type: 'tr',
- value: params.rotation,
+ value: {
+ a: params.value as number,
+ },
},
};
diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.ts
index ba18c4f04c..c9e30bc3d2 100644
--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.ts
+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.ts
@@ -1,26 +1,55 @@
-import { CommandType, ICommand, ICommandService, IUndoRedoService } from '@univerjs/core';
+import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
import { ISetWorksheetColWidthMutationParams, SetWorksheetColWidthMutation, SetWorksheetColWidthMutationFactory } from '../Mutations/set-worksheet-col-width.mutation';
+import { ISelectionManager } from '../../Services/tokens';
+/**
+ * TODO@Dushusir 支持多个选区
+ */
export interface SetWorksheetColWidthCommandParams {
- workbookId: string;
- worksheetId: string;
- colIndex: number;
- colWidth: number[];
+ workbookId?: string;
+ worksheetId?: string;
+ colIndex?: number;
+ value: number | number[];
}
export const SetWorksheetColWidthCommand: ICommand = {
type: CommandType.COMMAND,
id: 'sheet.command.set-worksheet-col-width',
handler: async (accessor: IAccessor, params: SetWorksheetColWidthCommandParams) => {
+ const selectionManager = accessor.get(ISelectionManager);
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const selections = selectionManager.getCurrentSelections();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const range = selections[0];
+
+ let { worksheetId, workbookId, colIndex, value } = params || {};
+ if (!workbookId) {
+ workbookId = workbook.getUnitId();
+ }
+
+ if (!worksheetId) {
+ worksheetId = workbook.getActiveSheet().getSheetId();
+ }
+
+ if (!colIndex) {
+ colIndex = range.startColumn;
+ }
+
+ if (!Array.isArray(value)) {
+ if (typeof value === 'object') {
+ value = 1;
+ }
+ value = new Array(range.endColumn - range.startColumn + 1).fill(value);
+ }
const redoMutationParams: ISetWorksheetColWidthMutationParams = {
- worksheetId: params.worksheetId,
- workbookId: params.workbookId,
- colIndex: params.colIndex,
- colWidth: params.colWidth,
+ worksheetId,
+ workbookId,
+ colIndex,
+ colWidth: value,
};
const undoMutationParams: ISetWorksheetColWidthMutationParams = SetWorksheetColWidthMutationFactory(accessor, redoMutationParams);
const result = commandService.executeCommand(SetWorksheetColWidthMutation.id, redoMutationParams);
diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts
index ea8b666688..c9d8311d1e 100644
--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts
+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts
@@ -1,26 +1,56 @@
-import { CommandType, ICommand, ICommandService, IUndoRedoService } from '@univerjs/core';
+import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
import { ISetWorksheetRowHeightMutationParams, SetWorksheetRowHeightMutation, SetWorksheetRowHeightMutationFactory } from '../Mutations/set-worksheet-row-height.mutation';
+import { ISelectionManager } from '../../Services/tokens';
+/**
+ * TODO@Dushusir 支持多个选区
+ */
export interface SetWorksheetRowHeightCommandParams {
- workbookId: string;
- worksheetId: string;
- rowIndex: number;
- rowHeight: number[];
+ workbookId?: string;
+ worksheetId?: string;
+ rowIndex?: number;
+ value: number | number[] | string | string[];
}
export const SetWorksheetRowHeightCommand: ICommand = {
type: CommandType.COMMAND,
id: 'sheet.command.set-worksheet-row-height',
handler: async (accessor: IAccessor, params: SetWorksheetRowHeightCommandParams) => {
+ const selectionManager = accessor.get(ISelectionManager);
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const selections = selectionManager.getCurrentSelections();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const range = selections[0];
+ let { worksheetId, workbookId, rowIndex, value } = params;
+ if (!workbookId) {
+ workbookId = workbook.getUnitId();
+ }
+
+ if (!worksheetId) {
+ worksheetId = workbook.getActiveSheet().getSheetId();
+ }
+
+ if (!rowIndex) {
+ rowIndex = range.startRow;
+ }
+
+ if (!Array.isArray(value)) {
+ if (typeof value === 'object') {
+ value = 1;
+ }
+ value = new Array(range.endRow - range.startRow + 1).fill(value);
+ }
+
+ value = value.map((v) => (typeof v === 'string' ? parseInt(v, 10) : v));
const redoMutationParams: ISetWorksheetRowHeightMutationParams = {
- worksheetId: params.worksheetId,
- workbookId: params.workbookId,
- rowIndex: params.rowIndex,
- rowHeight: params.rowHeight,
+ worksheetId,
+ workbookId,
+ rowIndex,
+ rowHeight: value as number[],
};
const undoMutationParams: ISetWorksheetRowHeightMutationParams = SetWorksheetRowHeightMutationFactory(accessor, redoMutationParams);
const result = commandService.executeCommand(SetWorksheetRowHeightMutation.id, redoMutationParams);
diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
index 62ed24ef83..b0563e0c67 100644
--- a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
@@ -7,7 +7,18 @@ import { SetWorksheetNameCommand } from '../Commands/Commands/set-worksheet-name
import { SetWorksheetNameMutation } from '../Commands/Mutations/set-worksheet-name.mutation';
import { SetWorksheetActivateCommand } from '../Commands/Commands/set-worksheet-activate.command';
import { SetWorksheetActivateMutation } from '../Commands/Mutations/set-worksheet-activate.mutation';
-import { ISetStyleParams, SetStyleCommand } from '../Commands/Commands/set-style.command';
+import {
+ ISetStyleParams,
+ ResetBackgroundColorCommand,
+ ResetTextColorCommand,
+ SetBackgroundColorCommand,
+ SetHorizontalTextAlignCommand,
+ SetStyleCommand,
+ SetTextColorCommand,
+ SetTextRotationCommand,
+ SetTextWrapCommand,
+ SetVerticalTextAlignCommand,
+} from '../Commands/Commands/set-style.command';
import { SetRangeStyleMutation } from '../Commands/Mutations/set-range-styles.mutation';
import { ISetRangeFormattedValueParams, SetRangeFormattedValueCommand } from '../Commands/Commands/set-range-formatted-value.command';
import { TrimWhitespaceCommand } from '../Commands/Commands/trim-whitespace.command';
@@ -31,10 +42,11 @@ import { DeleteRangeMutation } from '../Commands/Mutations/delete-range.mutation
import { SetRangeFormattedValueMutation } from '../Commands/Mutations/set-range-formatted-value.mutation';
import { IInsertRangeMoveRightParams, InsertRangeMoveRightCommand } from '../Commands/Commands/insert-range-move-right.command';
import { DeleteRangeMoveLeftCommand, IDeleteRangeMoveLeftParams } from '../Commands/Commands/delete-range-move-left.command';
-import { DeleteRangeMoveTopCommand, IDeleteRangeMoveTopParams } from '../Commands/Commands/delete-range-move-top.command';
+import { DeleteRangeMoveUpCommand, IDeleteRangeMoveUpParams } from '../Commands/Commands/delete-range-move-up.command';
import { IInsertRangeMoveBottomParams, InsertRangeMoveBottomCommand } from '../Commands/Commands/insert-range-move-bottom.command';
import { SetWorksheetOrderCommand } from '../Commands/Commands/set-worksheet-order.command';
import { SetWorksheetOrderMutation } from '../Commands/Mutations/set-worksheet-order.mutation';
+import { SetBorderColorCommand, SetBorderCommand, SetBorderPositionCommand, SetBorderStyleCommand } from '../Commands/Commands/set-border-command';
export interface IStyleTypeValue<T> {
type: keyof IStyleData;
@@ -86,10 +98,24 @@ export class BasicWorksheetController extends Disposable implements IDisposable
InsertRangeMoveBottomCommand,
InsertRangeMutation,
DeleteRangeMoveLeftCommand,
- DeleteRangeMoveTopCommand,
+ DeleteRangeMoveUpCommand,
DeleteRangeMutation,
SetRangeFormattedValueCommand,
SetRangeFormattedValueMutation,
+
+ SetTextColorCommand,
+ SetBackgroundColorCommand,
+ SetTextWrapCommand,
+ SetTextRotationCommand,
+ ResetTextColorCommand,
+ ResetBackgroundColorCommand,
+ SetHorizontalTextAlignCommand,
+ SetVerticalTextAlignCommand,
+
+ SetBorderCommand,
+ SetBorderColorCommand,
+ SetBorderStyleCommand,
+ SetBorderPositionCommand,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
@@ -163,13 +189,13 @@ export class BasicWorksheetController extends Disposable implements IDisposable
return this._commandService.executeCommand(DeleteRangeMoveLeftCommand.id, options);
}
- async deleteRangeMoveTop(workbookId: string, worksheetId: string, range: IRangeData): Promise<boolean> {
- const options: IDeleteRangeMoveTopParams = {
+ async deleteRangeMoveUp(workbookId: string, worksheetId: string, range: IRangeData): Promise<boolean> {
+ const options: IDeleteRangeMoveUpParams = {
workbookId,
worksheetId,
range,
};
- return this._commandService.executeCommand(DeleteRangeMoveTopCommand.id, options);
+ return this._commandService.executeCommand(DeleteRangeMoveUpCommand.id, options);
}
/**
diff --git a/packages/base-sheets/src/Controller/RightMenuController.ts b/packages/base-sheets/src/Controller/RightMenuController.ts
deleted file mode 100644
index 68f554ace2..0000000000
--- a/packages/base-sheets/src/Controller/RightMenuController.ts
+++ /dev/null
@@ -1,147 +0,0 @@
-import { Inject, SkipSelf } from '@wendellhu/redi';
-import { ICommandService, ICurrentUniverService, ObserverManager, UIObserver } from '@univerjs/core';
-import { SelectionController } from './Selection/SelectionController';
-import { SelectionModel } from '../Model/SelectionModel';
-import { ISelectionManager } from '../Services/tokens';
-import { SelectionManager } from './Selection';
-import { HideColumnController } from './HideColumnController';
-import { ClearSelectionContentCommand } from '../Commands/Commands/clear-selection-content.command';
-
-export class RightMenuController {
- constructor(
- @SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,
- @ISelectionManager private readonly _selectionManager: SelectionManager,
- @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
- @Inject(HideColumnController) private readonly _hideColumnController: HideColumnController,
- @ICommandService private readonly _commandService: ICommandService
- ) {}
-
- listenEventManager() {
- this._globalObserverManager.requiredObserver<UIObserver<string>>('onUIChangeObservable', 'core').add((msg: UIObserver<string>) => {
- switch (msg.name) {
- case 'insertRow':
- this.insertRow();
- break;
- case 'insertColumn':
- this.insertColumn();
- break;
- case 'deleteRow':
- this.deleteRow();
- break;
- case 'deleteColumn':
- this.deleteColumn();
- break;
- case 'hideColumn':
- this.hideColumn();
- break;
- case 'moveTop':
- this.deleteCellTop();
- break;
- case 'moveLeft':
- this.deleteCellLeft();
- break;
- case 'clearContent':
- this.clearContent();
- break;
- case 'setRowHeight':
- this.setRowHeight(msg.value!);
- break;
- case 'setColumnWidth':
- this.setColumnWidth(msg.value!);
- break;
- }
- });
- }
-
- insertRow = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet?.insertRowBefore(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1);
- }
- };
-
- deleteRow = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet?.deleteRows(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1);
- }
- };
-
- insertColumn = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet.insertColumnBefore(selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1);
- }
- };
-
- deleteColumn = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet.deleteColumns(selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1);
- }
- };
-
- hideColumn = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- this._hideColumnController.hideColumns(sheet.getSheetId(), selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1);
- }
- };
-
- clearContent = () => {
- // TODO: @wzhudev: should not call a command directly. Instead, it should invoke a method on XXXController and the controller would trigger a command.
- // Only command should be resonsible for triggering commands.
- this._commandService.executeCommand(ClearSelectionContentCommand.id);
- };
-
- deleteCellLeft = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet.getRange(selections[0]).deleteCells(0);
- }
- };
-
- deleteCellTop = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet.getRange(selections[0]).deleteCells(1);
- }
- };
-
- setColumnWidth(width: string) {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet.setColumnWidth(selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1, Number(width));
- }
- }
-
- setRowHeight(height: string) {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet.setRowHeights(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1, Number(height));
- }
- }
-
- private _getSelections() {
- const controls = this._selectionManager.getCurrentControls();
- const selections = controls?.map((control: SelectionController) => {
- const model: SelectionModel = control.model;
- return {
- startRow: model.startRow,
- startColumn: model.startColumn,
- endRow: model.endRow,
- endColumn: model.endColumn,
- };
- });
- return selections;
- }
-}
diff --git a/packages/base-sheets/src/Controller/ToolbarController.ts b/packages/base-sheets/src/Controller/ToolbarController.ts
deleted file mode 100644
index 9e307f011f..0000000000
--- a/packages/base-sheets/src/Controller/ToolbarController.ts
+++ /dev/null
@@ -1,264 +0,0 @@
-import {
- BorderType,
- HorizontalAlign,
- UIObserver,
- VerticalAlign,
- WrapStrategy,
- ObserverManager,
- ICurrentUniverService,
- ICommandService,
- UndoCommand,
- RedoCommand,
- IColorStyle,
-} from '@univerjs/core';
-import { Inject, SkipSelf } from '@wendellhu/redi';
-
-import { SelectionController } from './Selection/SelectionController';
-
-import { SelectionModel } from '../Model';
-import { ISelectionManager } from '../Services/tokens';
-import { CellEditorController } from './CellEditorController';
-import { SelectionManager } from './Selection';
-import { BasicWorksheetController, IStyleTypeValue } from './BasicWorksheet.controller';
-
-export interface BorderInfo {
- type: BorderType;
- color: string;
- style: number;
-}
-
-export class ToolbarController {
- constructor(
- @SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,
- @ICommandService private readonly _commandService: ICommandService,
- @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
- @ISelectionManager private readonly _selectionManager: SelectionManager,
- @Inject(CellEditorController) private readonly _cellEditorController: CellEditorController,
- @Inject(BasicWorksheetController) private readonly _basicWorksheetController: BasicWorksheetController
- ) {
- this._initialize();
- }
-
- listenEventManager() {
- const cellEditorController = this._cellEditorController;
- this._globalObserverManager.requiredObserver<UIObserver<number>>('onUIChangeObservable', 'core').add((msg) => {
- switch (msg.name) {
- case 'undo':
- this.setUndo();
- break;
- case 'redo':
- this.setRedo();
- break;
- }
- });
-
- this._globalObserverManager.requiredObserver<UIObserver<number>>('onUIChangeObservable', 'core').add((msg) => {
- if (cellEditorController.getEditMode()) return;
- switch (msg.name) {
- case 'fontSize':
- this.setFontSize(msg.value!);
- break;
- case 'textRotation':
- this.setTextRotation(msg.value!);
- break;
- case 'wrapStrategy':
- this.setWrapStrategy(msg.value!);
- break;
- case 'verticalAlignment':
- this.setVerticalAlignment(msg.value!);
- break;
- case 'horizontalAlignment':
- this.setHorizontalAlignment(msg.value!);
- break;
- }
- });
-
- this._globalObserverManager.requiredObserver<UIObserver<BorderInfo>>('onUIChangeObservable', 'core').add((msg) => {
- if (cellEditorController.getEditMode()) return;
- switch (msg.name) {
- case 'borderInfo':
- this.setBorder(msg.value!);
- break;
- }
- });
-
- this._globalObserverManager.requiredObserver<UIObserver<string>>('onUIChangeObservable', 'core').add((msg) => {
- if (cellEditorController.getEditMode()) return;
- switch (msg.name) {
- case 'fontFamily':
- this.setFontFamily(msg.value!);
- break;
- case 'fontColor':
- this.setFontColor(msg.value!);
- break;
- case 'background':
- this.setBackground(msg.value!);
- break;
- case 'merge':
- this.setMerge(msg.value!);
- break;
- }
- });
-
- this._globalObserverManager.requiredObserver<UIObserver<boolean>>('onUIChangeObservable', 'core').add((msg) => {
- if (cellEditorController.getEditMode()) return;
- switch (msg.name) {
- case 'fontWeight':
- this.setFontWeight(msg.value!);
- break;
- case 'fontStyle':
- this.setFontStyle(msg.value!);
- break;
- case 'strikeThrough':
- this.setStrikeThrough(msg.value!);
- break;
- case 'underLine':
- this.setUnderline(msg.value!);
- break;
- }
- });
- }
-
- _initialize() {
- // this._plugin.getObserver('onAfterChangeFontFamilyObservable')?.add((value: string) => {
- // this._plugin.getCellEditorController().richText.cellTextStyle.updateFormat('ff', value);
- // });
- // this._plugin.getObserver('onAfterChangeFontItalicObservable')?.add((value: boolean) => {
- // this._plugin.getCellEditorController().richText.cellTextStyle.updateFormat('it', value ? '1' : '0');
- // });
- // this._plugin.getObserver('onAfterChangeFontStrikethroughObservable')?.add((value: boolean) => {
- // this._plugin.getCellEditorController().richText.cellTextStyle.updateFormat('cl', value ? '1' : '0');
- // });
- // this._plugin.getObserver('onAfterChangeFontUnderlineObservable')?.add((value: boolean) => {
- // this._plugin.getCellEditorController().richText.cellTextStyle.updateFormat('un', value ? '1' : '0');
- // });
- // this._plugin.getObserver('onAfterChangeFontColorObservable')?.add((value: string) => {
- // this._plugin.getCellEditorController().richText.cellTextStyle.updateFormat('fc', value);
- // });
- // this._plugin.getObserver('onAfterChangeFontBackgroundObservable')?.add((value: string) => {
- // this._plugin.getCellEditorController().richText.cellTextStyle.updateFormat('bg', value);
- // });
- }
-
- private setRedo() {
- this._commandService.executeCommand(RedoCommand.id);
- }
-
- private setUndo() {
- this._commandService.executeCommand(UndoCommand.id);
- }
-
- private setFontColor(value: string) {
- this._selectionManager.getActiveRangeList()?.setFontColor(value);
- }
-
- private setBackground(value: string) {
- const range = this._selectionManager.getActiveRangeData();
- if (!range) return;
- const workbookId = this._currentUniverService.getCurrentUniverSheetInstance().getUnitId();
- const worksheetId = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();
- const style: IStyleTypeValue<IColorStyle> = {
- type: 'bg',
- value: {
- rgb: value,
- },
- };
- this._basicWorksheetController.setStyle(workbookId, worksheetId, style, [range]);
- }
-
- private setFontSize(value: number) {
- const range = this._selectionManager.getActiveRangeData();
- if (!range) return;
- const workbookId = this._currentUniverService.getCurrentUniverSheetInstance().getUnitId();
- const worksheetId = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();
- // const style: IStyleTypeValue<number> = {
- // type: 'fs',
- // value,
- // };
- // this._basicWorksheetController.setStyle(workbookId, worksheetId, style, [range]);
- this._basicWorksheetController.trimWhitespace(workbookId, worksheetId, [range]);
- }
-
- private setFontFamily(value: string) {
- this._selectionManager.getActiveRangeList()?.setFontFamily(value);
- }
-
- private setFontWeight(value: boolean) {
- this._selectionManager.getActiveRangeList()?.setFontWeight(value);
- }
-
- private setFontStyle(value: boolean) {
- this._selectionManager.getActiveRangeList()?.setFontStyle(value);
- }
-
- private setStrikeThrough(value: boolean) {
- this._selectionManager.getActiveRangeList()?.setStrikeThrough(value);
- }
-
- private setUnderline(value: boolean) {
- this._selectionManager.getActiveRangeList()?.setUnderline(value);
- }
-
- private setMerge(value: string) {
- const currentRange = this._selectionManager.getActiveRange();
-
- switch (value) {
- case 'all':
- currentRange?.merge();
- break;
-
- case 'vertical':
- currentRange?.mergeVertically();
- break;
-
- case 'horizontal':
- currentRange?.mergeAcross();
- break;
-
- case 'cancel':
- currentRange?.breakApart();
- break;
-
- default:
- break;
- }
- }
-
- private setHorizontalAlignment(value: HorizontalAlign) {
- this._selectionManager.getActiveRangeList()?.setHorizontalAlignment(value);
- }
-
- private setVerticalAlignment(value: VerticalAlign) {
- this._selectionManager.getActiveRangeList()?.setVerticalAlignment(value);
- }
-
- private setWrapStrategy(value: WrapStrategy) {
- this._selectionManager.getActiveRangeList()?.setWrapStrategy(value);
- }
-
- private setTextRotation(value: number | string) {
- if (value === 'v') {
- this._selectionManager.getActiveRangeList()?.setVerticalText(1);
- } else {
- this._selectionManager.getActiveRangeList()?.setTextRotation(value as number);
- }
- }
-
- private setBorder(info: BorderInfo) {
- const controls = this._selectionManager.getCurrentControls();
-
- if (controls && controls.length > 0) {
- controls?.forEach((control: SelectionController) => {
- const model: SelectionModel = control.model;
- const range = {
- startRow: model.startRow,
- startColumn: model.startColumn,
- endRow: model.endRow,
- endColumn: model.endColumn,
- };
-
- this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet().getRange(range).setBorderByType(info.type, info.color, info.style);
- });
- }
- }
-}
diff --git a/packages/base-sheets/src/Controller/index.ts b/packages/base-sheets/src/Controller/index.ts
index 5898f55120..092ec83edd 100644
--- a/packages/base-sheets/src/Controller/index.ts
+++ b/packages/base-sheets/src/Controller/index.ts
@@ -2,11 +2,9 @@
export * from './AntLineController';
export * from './CellEditorController';
export * from './CountBarController';
-export * from './RightMenuController';
export * from './Selection/index';
export * from './SheetBarController';
export * from './SheetContainerController';
-export * from './ToolbarController';
export * from './EditTooltipsController';
export * from './HideColumnController';
export * from './BasicWorksheet.controller';
diff --git a/packages/base-sheets/src/Services/TODO.md b/packages/base-sheets/src/Services/TODO.md
new file mode 100644
index 0000000000..f7383b66c0
--- /dev/null
+++ b/packages/base-sheets/src/Services/TODO.md
@@ -0,0 +1 @@
+- [ ] maybe the status managers could be merged into a single status service?
\ No newline at end of file
diff --git a/packages/base-sheets/src/Services/align-style-manager.service.ts b/packages/base-sheets/src/Services/align-style-manager.service.ts
new file mode 100644
index 0000000000..4aef5541a1
--- /dev/null
+++ b/packages/base-sheets/src/Services/align-style-manager.service.ts
@@ -0,0 +1,21 @@
+import { HorizontalAlign } from '@univerjs/core';
+import { IDisposable } from '@wendellhu/redi';
+import { BehaviorSubject } from 'rxjs';
+
+export class AlignStyleManagerService implements IDisposable {
+ private readonly _alignInfo = {
+ horizontal: HorizontalAlign.LEFT,
+ vertical: 'top',
+ };
+
+ private readonly _alignInfo$ = new BehaviorSubject(this._alignInfo);
+
+ // eslint-disable-next-line @typescript-eslint/member-ordering
+ readonly alignInfo$ = this._alignInfo$.asObservable();
+
+ dispose(): void {
+ this._alignInfo$.complete();
+ }
+
+ setHorizontalAlign(horizontal: HorizontalAlign): void {}
+}
diff --git a/packages/base-sheets/src/Services/border-style-manager.service.ts b/packages/base-sheets/src/Services/border-style-manager.service.ts
new file mode 100644
index 0000000000..7a4d5d5b43
--- /dev/null
+++ b/packages/base-sheets/src/Services/border-style-manager.service.ts
@@ -0,0 +1,47 @@
+import { BehaviorSubject } from 'rxjs';
+import { BorderStyleTypes, BorderType } from '@univerjs/core';
+import { IDisposable } from '@wendellhu/redi';
+
+export interface IBorderInfo {
+ type: BorderType;
+ color: string;
+ style: BorderStyleTypes;
+}
+
+/**
+ * This service is for managing settings border style status.
+ */
+export class BorderStyleManagerService implements IDisposable {
+ private readonly _borderInfo: IBorderInfo = {
+ type: BorderType.ALL,
+ color: '#000000',
+ style: BorderStyleTypes.THIN,
+ };
+
+ private readonly _borderInfo$ = new BehaviorSubject<IBorderInfo>(this._borderInfo);
+
+ // eslint-disable-next-line @typescript-eslint/member-ordering
+ readonly borderInfo$ = this._borderInfo$.asObservable();
+
+ dispose(): void {
+ this._borderInfo$.complete();
+ }
+
+ setColor(color: string): void {
+ this._borderInfo.color = color;
+ this.refresh();
+ }
+
+ setStyle(style: BorderStyleTypes): void {
+ this._borderInfo.style = style;
+ this.refresh();
+ }
+
+ getBorderInfo(): Readonly<IBorderInfo> {
+ return this._borderInfo;
+ }
+
+ private refresh(): void {
+ this._borderInfo$.next(this._borderInfo);
+ }
+}
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.ts
index d44fa0c931..598523f54b 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/SheetPlugin.ts
@@ -5,11 +5,9 @@ import { Dependency, Inject, Injector } from '@wendellhu/redi';
import { SheetPluginObserve, uninstall } from './Basics/Observer';
import { CanvasView } from './View/CanvasView';
import {
- RightMenuController,
SheetBarController,
CellEditorController,
SheetContainerController,
- ToolbarController,
CountBarController,
EditTooltipsController,
SelectionManager,
@@ -27,6 +25,7 @@ import { RowTitleController } from './Controller/Selection/RowTitleController';
import { ColumnRulerManager } from './Basics/Register/ColumnRegister';
import { HideColumnRulerFactory } from './Basics/Register/HideColumnRuler';
import { BasicWorksheetController } from './Controller/BasicWorksheet.controller';
+import { BorderStyleManagerService } from './Services/border-style-manager.service';
/**
* The main sheet base, construct the sheet container and layout, mount the rendering engine
@@ -38,12 +37,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
private _canvasEngine: Engine;
- // TODO: @wzhudev these controllers should be removed finally after we completely refactored base-sheet plugin
-
- private _rightMenuController: RightMenuController;
-
- private _toolbarController: ToolbarController;
-
private _editTooltipsController: EditTooltipsController;
private _formulaBarController: FormulaBarController;
@@ -118,8 +111,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
this._formulaBarController = this._injector.get(FormulaBarController);
this._editTooltipsController = this._injector.get(EditTooltipsController);
this._sheetBarController = this._injector.get(SheetBarController);
- this._toolbarController = this._injector.get(ToolbarController);
- this._rightMenuController = this._injector.get(RightMenuController);
this._countBarController = this._injector.get(CountBarController);
this._hideColumnController = this._injector.get(HideColumnController);
@@ -161,8 +152,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
// TODO: move these init to controllers not here
this._countBarController.listenEventManager();
this._sheetBarController.listenEventManager();
- this._toolbarController.listenEventManager();
- this._rightMenuController.listenEventManager();
}
/** @deprecated move to DI system */
@@ -179,8 +168,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
[FormulaBarController],
[EditTooltipsController],
[SheetBarController],
- [ToolbarController],
- [RightMenuController],
[CountBarController],
// TODO@huwenzhao: this is a temporary solution
@@ -200,6 +187,8 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
[BasicWorksheetController],
[BasicWorkbookController],
+
+ [BorderStyleManagerService],
];
dependencies.forEach((d) => {
diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.ts
index 291bc2d336..e46df7ca75 100644
--- a/packages/base-sheets/src/index.ts
+++ b/packages/base-sheets/src/index.ts
@@ -3,7 +3,15 @@ export * from './Model';
export * from './Controller';
export * from './Basics';
export * from './View';
+
+// #region services
+
export { ICanvasView, ISelectionManager } from './Services/tokens';
+export { BorderStyleManagerService } from './Services/border-style-manager.service';
+
+// #endregion
+
+// #region commands
// mutations
export { RemoveSheetMutation, RemoveSheetUndoMutationFactory } from './Commands/Mutations/remove-sheet.mutation';
@@ -26,12 +34,12 @@ export {
SetFontSizeCommand,
SetTextColorCommand,
SetBackgroundColorCommand,
- SetCellBorderCommand,
SetTextRotationCommand,
SetHorizontalTextAlignCommand,
- SetSpanCommand,
SetTextWrapCommand,
SetVerticalTextAlignCommand,
+ ResetTextColorCommand,
+ ResetBackgroundColorCommand,
} from './Commands/Commands/set-style.command';
export { InsertSheetCommand } from './Commands/Commands/insert-sheet.command';
export { SetWorksheetActivateCommand } from './Commands/Commands/set-worksheet-activate.command';
@@ -39,4 +47,24 @@ export { SetWorksheetOrderCommand } from './Commands/Commands/set-worksheet-orde
export { SetWorksheetRowHeightCommand } from './Commands/Commands/set-worksheet-row-height.command';
export { SetWorksheetColWidthCommand } from './Commands/Commands/set-worksheet-col-width.command';
export { DeleteRangeCommand } from './Commands/Commands/delete-range.command';
+export { DeleteRangeMoveLeftCommand } from './Commands/Commands/delete-range-move-left.command';
+export { DeleteRangeMoveUpCommand } from './Commands/Commands/delete-range-move-up.command';
export { RemoveRowCommand, RemoveColCommand } from './Commands/Commands/remove-row-col.command';
+export { InsertColCommand, InsertRowCommand, InsertColCommandParams, InsertRowCommandParams } from './Commands/Commands/insert-row-col.command';
+export { ClearSelectionContentCommand } from './Commands/Commands/clear-selection-content.command';
+export {
+ SetBorderColorCommand,
+ SetBorderCommand,
+ SetBorderPositionCommand,
+ SetBorderStyleCommand,
+ ISetBorderColorCommandParams,
+ ISetBorderCommandParams,
+ ISetBorderPositionCommandParams,
+ ISetBorderStyleCommandParams,
+} from './Commands/Commands/set-border-command';
+
+// #endregion
+export { SetWorksheetRowHideCommand } from './Commands/Commands/set-worksheet-row-hide.command';
+export { SetWorksheetRowShowCommand } from './Commands/Commands/set-worksheet-row-show.command';
+export { RemoveSheetCommand } from './Commands/Commands/remove-sheet.command';
+export { SetWorksheetHideCommand } from './Commands/Commands/set-worksheet-hide.command';
diff --git a/packages/base-slides/package.json b/packages/base-slides/package.json
index db282bb98f..bc472772ed 100644
--- a/packages/base-slides/package.json
+++ b/packages/base-slides/package.json
@@ -57,7 +57,7 @@
"@univerjs/core": "workspace:^0.0.1",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1",
- "@wendellhu/redi": "^0.12.6"
+ "@wendellhu/redi": "^0.12.7"
}
}
\ No newline at end of file
diff --git a/packages/base-ui/package.json b/packages/base-ui/package.json
index 91cf86837d..d835e3814b 100644
--- a/packages/base-ui/package.json
+++ b/packages/base-ui/package.json
@@ -59,7 +59,7 @@
"dependencies": {
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"preact": "^10.12.1",
"react-colorful": "^5.3.0",
"rxjs": "^7.8.1"
diff --git a/packages/base-ui/src/BaseComponent.ts b/packages/base-ui/src/BaseComponent.ts
index 27d6b5c8bc..18b63c4e16 100644
--- a/packages/base-ui/src/BaseComponent.ts
+++ b/packages/base-ui/src/BaseComponent.ts
@@ -2,7 +2,6 @@ import { ComponentClass } from 'preact';
import { ForwardFn } from 'preact/compat';
import { BasePlugin } from '@univerjs/core';
import { Context } from '@univerjs/core/src/Basics/Context';
-import { Injector } from '@wendellhu/redi';
import { Description } from './Interfaces';
// TODO Button const enum; BaseComponentSheet => BaseComponentXXX
@@ -13,8 +12,6 @@ export interface BaseComponentSheet extends BasePlugin {
getComponentFactory(): BaseComponentFactory;
}
export interface BaseComponentProps {
- injector: Injector;
-
getComponent?: (ref: any) => void; //获取自身组件
id?: string; // 组件id
diff --git a/packages/base-ui/src/Common/ComponentManager.ts b/packages/base-ui/src/Common/ComponentManager.ts
index dac4f336cb..a5ea699b87 100644
--- a/packages/base-ui/src/Common/ComponentManager.ts
+++ b/packages/base-ui/src/Common/ComponentManager.ts
@@ -53,6 +53,7 @@ export interface ICustomComponent {
name: string;
props?: IKeyValue;
}
+
export type ComponentList = Map<string, Function>;
export class ComponentManager {
diff --git a/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx b/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
index 1571ef6ceb..08123052ff 100644
--- a/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
+++ b/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
@@ -1,5 +1,6 @@
-import { Component, createRef } from 'preact';
+import { Component, JSX, createRef } from 'preact';
import { BaseColorPickerProps, ColorPickerComponent, JSXComponent } from '../..';
+import { ICustomComponentProps } from '../../services/menu/menu';
import { Button, Tooltip } from '../index';
import { ColorPickerPanel } from './ColorPickerPanel';
import { CustomLabel } from '../CustomLabel';
@@ -27,7 +28,7 @@ interface IState {
root: Element | null;
}
-class ColorPicker extends Component<BaseColorPickerProps, IState> {
+class ColorPicker extends Component<BaseColorPickerProps & ICustomComponentProps<string>, IState> {
ulRef = createRef();
constructor(props: BaseColorPickerProps) {
@@ -66,8 +67,8 @@ class ColorPicker extends Component<BaseColorPickerProps, IState> {
* @eventProperty
*/
onClick = (color: string, e: MouseEvent) => {
- this.props.onClick && this.props.onClick(color, e);
- // this.hideSelect();
+ this.props.onClick?.(color, e);
+ this.props.onValueChange?.(color);
};
/**
@@ -134,7 +135,7 @@ class ColorPicker extends Component<BaseColorPickerProps, IState> {
});
};
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
@@ -161,8 +162,7 @@ class ColorPicker extends Component<BaseColorPickerProps, IState> {
className={styles.pickerSwatchBtn}
style={{ background: item }}
onClick={(e: MouseEvent) => {
- // this.hideSelect();
- this.props.onClick && this.props.onClick(item, e);
+ this.onClick(item, e);
}}
/>
</Tooltip>
diff --git a/packages/base-ui/src/Components/CustomLabel/CustomLabel.module.less b/packages/base-ui/src/Components/CustomLabel/CustomLabel.module.less
new file mode 100644
index 0000000000..9b3283e96a
--- /dev/null
+++ b/packages/base-ui/src/Components/CustomLabel/CustomLabel.module.less
@@ -0,0 +1,19 @@
+.color-select {
+ position: relative;
+
+ .color-select-line {
+ position: absolute;
+ width: 15px;
+ height: 5px;
+ bottom: 0px;
+ left: 50%;
+ transform: translate(-50%, 0);
+ }
+}
+
+.font-select {
+ width: 120px;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ white-space: nowrap;
+}
\ No newline at end of file
diff --git a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
index 5e6dd25287..0ddd2108fe 100644
--- a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
+++ b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
@@ -1,28 +1,123 @@
-import { isValidElement } from 'preact';
+import { Component, isValidElement, JSX } from 'preact';
import { useContext } from 'preact/hooks';
-import { AppContext, ICustomComponent } from '../../Common';
+
+import { AppContext, AppContextValues, ICustomComponent } from '../../Common';
import { IBaseCustomLabelProps } from '../../Interfaces';
+import { DisplayTypes } from '../Select';
+
+import styles from './CustomLabel.module.less';
+import { IMenuSelectorItem } from '../../services/menu/menu';
+import { Item } from '../Item/Item';
+import { Input } from '../Input/input';
+
+function getLocale(context: Partial<AppContextValues>, name: string) {
+ return context.localeService?.t(name);
+}
+
+export interface INeoCustomLabelProps {
+ value?: string | number | undefined;
+ selected?: boolean;
+ onChange?(v: string | number): void;
+}
+
+/**
+ * The component to render toolbar item label and menu item label.
+ * @param props
+ * @returns
+ */
+export function NeoCustomLabel(props: Pick<IMenuSelectorItem<unknown>, 'label' | 'icon' | 'display' | 'title'> & INeoCustomLabelProps): JSX.Element | null {
+ const context = useContext(AppContext);
+ const { display, value, title, icon, label, onChange, selected } = props;
+
+ if (display === DisplayTypes.COLOR) {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ return <ColorSelect value={value as any} title={title} icon={icon} />;
+ }
+
+ if (display === DisplayTypes.FONT) {
+ return (
+ <div className={styles.fontSelect} style={{ fontFamily: value as string }}>
+ {getLocale(context, value as string)}
+ </div>
+ );
+ }
+
+ if (display === DisplayTypes.INPUT) {
+ return <Input onValueChange={(v) => onChange?.(v as unknown as string)} type="number" value={`${value}`} />;
+ }
+
+ if (display === DisplayTypes.ICON && icon) {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const LabelComponent = context.componentManager?.get(icon) as any;
+ if (LabelComponent) {
+ return <LabelComponent {...props} />;
+ }
+ }
+
+ if (display === DisplayTypes.CUSTOM && label) {
+ const labelName = typeof label === 'string' ? label : (label as ICustomComponent).name;
+ const customProps = (label as ICustomComponent).props ?? {};
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const LabelComponent = context.componentManager?.get(labelName) as any;
+ if (LabelComponent) {
+ return <LabelComponent {...customProps} {...props} />;
+ }
+ }
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const LabelComponent = icon ? (context.componentManager?.get(icon) as any) : null;
+ return <Item selected={selected} label={title} suffix={LabelComponent ? <LabelComponent /> : null} disabled={false}></Item>;
+}
+
+/** @deprecated */
export function CustomLabel(props: IBaseCustomLabelProps): JSX.Element | null {
const context = useContext(AppContext);
- const { label } = props;
+ const { label, display, onChange } = props;
function getLocale(name: string) {
return context.localeService?.t(name);
}
+ // the new way to render toolbar item type to replace Label prop
+ if (display === DisplayTypes.COLOR) {
+ return <ColorSelect value={props.label} title={props.label} />;
+ }
+
if (typeof label === 'string') {
return <>{getLocale(label)}</>;
}
+
if (isValidElement(label)) {
return label;
}
+
+ // other types of components and icon
if (label) {
const Label = context.componentManager?.get((label as ICustomComponent).name) as any;
if (Label) {
const props = (label as ICustomComponent).props ?? {};
- return <Label {...props} />;
+ return <Label onChange={onChange} {...props} />;
}
}
+
return null;
}
+
+export interface IColorSelectProps {
+ icon?: string;
+ title: string;
+ /** color */
+ value: string;
+}
+
+export class ColorSelect extends Component<IColorSelectProps> {
+ render() {
+ const { value, icon, title } = this.props;
+ return (
+ <div className={styles.colorSelect}>
+ <div>{icon ? <CustomLabel label={{ name: icon }} /> : title}</div>
+ <div className={styles.colorSelectLine} style={{ background: value }}></div>
+ </div>
+ );
+ }
+}
diff --git a/packages/base-ui/src/Components/Dropdown/Dropdown.tsx b/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
index 2206601a15..2e534777fc 100644
--- a/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
+++ b/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
@@ -1,4 +1,4 @@
-import { createRef } from 'preact';
+import { JSX, createRef } from 'preact';
import { PureComponent } from 'preact/compat';
import { Icon } from '..';
import { JSXComponent } from '../../BaseComponent';
@@ -46,7 +46,7 @@ export class Dropdown extends PureComponent<BaseDropdownProps, IState> {
}
};
- componentDidMount() {
+ override componentDidMount() {
const { placement } = this.props;
const style: Record<string, string | number> = { position: 'absolute' };
if (!placement || placement === 'Bottom') {
@@ -68,12 +68,12 @@ export class Dropdown extends PureComponent<BaseDropdownProps, IState> {
window.addEventListener('click', this.hideMenuClick, true);
}
- componentWillUnmount() {
+ override componentWillUnmount() {
window.removeEventListener('click', this.hideMenuClick, true);
}
render() {
- const { children, menu, showArrow, icon, tooltip } = this.props;
+ const { children, menu, showArrow, icon, tooltip, content } = this.props;
const { menuStyle } = this.state;
return (
@@ -84,14 +84,27 @@ export class Dropdown extends PureComponent<BaseDropdownProps, IState> {
{showArrow ? <Icon.Format.NextIcon /> : ''}
</div>
</Tooltip>
- {icon ? (
+ {icon && (
<div ref={this.IconRef} className={styles.dropIcon} onClick={this.handleSubClick}>
{icon}
</div>
- ) : (
- ''
)}
- <Menu onClick={menu.onClick} ref={this.MenuRef} menu={menu.menu} className={menu.className} style={{ ...menu.style, ...menuStyle }}></Menu>
+ {content}
+ <Menu
+ menuId={menu.menuId}
+ options={menu.options}
+ display={menu.display}
+ onClick={menu.onClick}
+ ref={this.MenuRef}
+ value={menu.value}
+ menu={menu.menu}
+ className={menu.className}
+ style={{ ...menu.style, ...menuStyle }}
+ onOptionSelect={(v) => {
+ menu.onOptionSelect?.(v);
+ this.hideMenu();
+ }}
+ ></Menu>
</div>
);
}
diff --git a/packages/base-ui/src/Components/Input/input.tsx b/packages/base-ui/src/Components/Input/input.tsx
index 9fc0c883fc..69ba5de8d7 100644
--- a/packages/base-ui/src/Components/Input/input.tsx
+++ b/packages/base-ui/src/Components/Input/input.tsx
@@ -61,10 +61,11 @@ export class Input extends Component<BaseInputProps, IState> {
};
handlePressEnter = (e: KeyboardEvent) => {
- const { onPressEnter } = this.props;
+ const { onPressEnter, onValueChange } = this.props;
if (e.key === 'Enter') {
onPressEnter?.(e);
this.ref.current.blur();
+ onValueChange?.(this.getValue());
}
};
@@ -76,11 +77,13 @@ export class Input extends Component<BaseInputProps, IState> {
onClick = (e: MouseEvent) => {
const { onClick } = this.props;
onClick?.(e);
+ e.stopPropagation();
};
onBlur = (e: FocusEvent) => {
- const { onBlur } = this.props;
+ const { onBlur, onValueChange } = this.props;
onBlur?.(e);
+ onValueChange?.(this.getValue());
};
// get input value
diff --git a/packages/base-ui/src/Components/Item/Item.tsx b/packages/base-ui/src/Components/Item/Item.tsx
index 6c81007bf7..89ba2085ab 100644
--- a/packages/base-ui/src/Components/Item/Item.tsx
+++ b/packages/base-ui/src/Components/Item/Item.tsx
@@ -11,27 +11,29 @@ export interface BaseItemProps extends BaseMenuItem {
border?: boolean;
}
+// TODO@wzhudev: move this component to another proper position. Now used by NeoCustomLabel component.
+
+/**
+ * This render as a label of MenuItem.
+ */
export class Item extends Component<BaseItemProps> {
render() {
const { selected, label, suffix, disabled } = this.props;
+
return (
<div className={joinClassNames(styles.selectItem, disabled ? styles.selectDisabledItem : '')}>
- {selected ? (
+ {selected && (
<span className={styles.selectItemSelected}>
<Icon.CorrectIcon />
</span>
- ) : (
- ''
)}
<span className={styles.selectItemContent}>
<CustomLabel label={label} />
</span>
- {suffix ? (
+ {suffix && (
<span className={styles.selectItemSuffix}>
<CustomLabel label={suffix} />
</span>
- ) : (
- ''
)}
</div>
);
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index 054b098cd3..c00c52115a 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -1,16 +1,24 @@
import { Component, ComponentChild, createRef } from 'preact';
import { Subscription } from 'rxjs';
-import { ICommandService } from '@univerjs/core';
+import { ICommandService, isRealNum } from '@univerjs/core';
+import { BaseMenuProps, BaseMenuItem, BaseMenuStyle } from '../../Interfaces';
import { joinClassNames } from '../../Utils';
-import { CustomLabel } from '../CustomLabel';
-
-import { BaseMenuProps, BaseMenuState, BaseMenuItem, BaseMenuStyle } from '../../Interfaces';
+import { AppContext } from '../../Common/AppContext';
+import { ICustomComponentOption, IDisplayMenuItem, IMenuButtonItem, IMenuItem, IMenuSelectorItem, IValueOption, MenuItemType, isValueOptions } from '../../services/menu/menu';
+import { CustomLabel, NeoCustomLabel } from '../CustomLabel/CustomLabel';
+import { IMenuService } from '../../services/menu/menu.service';
import styles from './index.module.less';
-import { IDisplayMenuItem } from '../../services/menu/menu.service';
-import AppContext from '../../Common/AppContext';
-export class Menu extends Component<BaseMenuProps, BaseMenuState> {
+export interface IBaseMenuState {
+ show: boolean;
+ posStyle: BaseMenuStyle;
+ menuItems: Array<IDisplayMenuItem<IMenuItem>>;
+}
+
+export class Menu extends Component<BaseMenuProps, IBaseMenuState> {
+ static override contextType = AppContext;
+
private _MenuRef = createRef<HTMLUListElement>();
private _refs: Menu[] = [];
@@ -20,6 +28,16 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
this.initialize();
}
+ override componentDidMount(): void {
+ this.getSubMenus();
+ }
+
+ override componentWillReceiveProps(nextProps: Readonly<BaseMenuProps>): void {
+ if (this.props.menuId !== nextProps.menuId) {
+ this.getSubMenus();
+ }
+ }
+
getMenuRef = () => this._MenuRef;
handleClick = (e: MouseEvent, item: BaseMenuItem, index: number) => {
@@ -92,29 +110,25 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
posStyle: style,
});
}
- // else {
- // if (curPosition.width > docPosition!.right) {
- // // 边界碰到univer-main-content右边界或者小于视口
- // style.right = '0';
- // style.left = 'auto';
- // } else {
- // style.left = '0';
- // style.right = 'auto';
- // }
- // if (curPosition.top >= docPosition.bottom) {
- // style.top = 'auto';
- // style.bottom = '100%';
- // }
- // }
};
+ handleItemClick = (item: IMenuButtonItem) => {
+ // When there is no need to execute the command, execute click
+ if (item.onClick) {
+ item.onClick();
+ }
+ this.showMenu(false);
+ };
+
+ // eslint-disable-next-line max-lines-per-function
render() {
- const { className = '', menuItems, style = '', menu, deep = 0 } = this.props;
- const { show, posStyle } = this.state;
+ const { context, props, state } = this;
+ const { className = '', style = '', menu, deep = 0, options, display, value } = props;
+ const { posStyle, show, menuItems } = state;
return (
<ul className={joinClassNames(styles.colsMenu, className)} style={{ ...style, ...posStyle, display: show ? 'block' : 'none' }} ref={this._MenuRef}>
- {/* NOTE: this will be dropped after we complete migrating to new UI system. */}
+ {/* legacy: render selections */}
{menu?.map((item: BaseMenuItem, index: number) => {
if (item.show === false) return;
return (
@@ -131,6 +145,7 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
}}
>
<CustomLabel label={item.label} />
+ {/* TODO: if the menu itself contains a submenu. It should be served as an `IMenuItem` not wrapped options. */}
{item.children ? (
<Menu
ref={(ele: Menu) => (this._refs[index] = ele)}
@@ -149,26 +164,93 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
</>
);
})}
- {menuItems?.map((item, index) => (
- <MenuItem menuItem={item} index={index} onClick={() => this.showMenu(false)} />
+ {options?.map((option: IValueOption | ICustomComponentOption, index: number) => {
+ // render value option
+ const isValueOption = isValueOptions(option);
+ if (isValueOption) {
+ return (
+ <li
+ className={joinClassNames(styles.colsMenuitem, option.disabled ? styles.colsMenuitemDisabled : '')}
+ onClick={() => {
+ if (option.value) {
+ this.props.onOptionSelect!(option);
+ }
+ }}
+ >
+ <NeoCustomLabel
+ selected={value === option.value}
+ value={option.value}
+ display={display}
+ label={option.label}
+ title={option.label}
+ icon={option.icon}
+ />
+ </li>
+ );
+ }
+
+ // custom component option
+ const CustomComponent = context.componentManager?.get(option.id);
+ return (
+ <li>
+ <CustomComponent
+ onValueChange={(v: string | number) => {
+ this.props.onOptionSelect!({ value: v, label: option.id });
+ this.showMenu(false);
+ }}
+ />
+ </li>
+ );
+ })}
+ {/* render submenus */}
+ {menuItems?.map((item: IDisplayMenuItem<IMenuItem>, index) => (
+ <MenuItem menuItem={item} index={index} onClick={this.handleItemClick.bind(this, item as IMenuButtonItem)} />
))}
</ul>
);
}
- protected override initialize() {
+ protected initialize() {
this.state = {
show: false,
posStyle: {},
+ menuItems: [],
};
}
+
+ private getSubMenus() {
+ const { menuId } = this.props;
+
+ if (menuId) {
+ const menuService: IMenuService = this.context.injector.get(IMenuService);
+ this.setState({
+ menuItems: menuService.getMenuItems(menuId),
+ });
+ }
+ }
}
-export class MenuItem extends Component<{ menuItem: IDisplayMenuItem; index: number; onClick: () => void }, { disabled: boolean }> {
+export interface IMenuItemProps {
+ menuItem: IDisplayMenuItem<IMenuItem>;
+ index: number;
+ onClick: () => void;
+}
+
+export interface IMenuItemState {
+ disabled: boolean;
+ menuItems: Array<IDisplayMenuItem<IMenuItem>>;
+ value: any;
+}
+
+// TODO: this component should have something in common with ToolbarItem
+
+export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
static override contextType = AppContext;
private disabledSubscription: Subscription | undefined;
+ private valueSubscription: Subscription | undefined;
+
private _refs: Menu[] = [];
constructor() {
@@ -176,61 +258,169 @@ export class MenuItem extends Component<{ menuItem: IDisplayMenuItem; index: num
this.state = {
disabled: false,
+ value: undefined,
+ menuItems: [],
};
}
mouseEnter = (e: MouseEvent, index: number) => {
- const { menuItem } = this.props;
- if (menuItem.subMenus) {
- this._refs[index].showMenu(true);
- }
+ this._refs[index]?.showMenu(true);
};
mouseLeave = (e: MouseEvent, index: number) => {
- const { menuItem } = this.props;
- if (menuItem.subMenus) {
- this._refs[index].showMenu(false);
- }
+ this._refs[index]?.showMenu(false);
};
override componentDidMount(): void {
- this.disabledSubscription = this.props.menuItem.disabled$?.subscribe((disabled) => {
+ const { menuItem } = this.props;
+
+ this.disabledSubscription = menuItem.disabled$?.subscribe((disabled) => {
this.setState({ disabled });
});
+
+ this.valueSubscription = menuItem.value$?.subscribe((value) => {
+ this.setState({ value });
+ });
+
+ this.getSubMenus();
}
override componentWillUnmount(): void {
this.disabledSubscription?.unsubscribe();
+ this.valueSubscription?.unsubscribe();
}
- override render(): ComponentChild {
- const { menuItem: item, index } = this.props;
+ override componentWillReceiveProps(nextProps: Readonly<IMenuItemProps>): void {
+ if (this.props.menuItem.id !== nextProps.menuItem.id) {
+ this.getSubMenus();
+ }
+ }
+
+ handleClick = (e: MouseEvent, item: IDisplayMenuItem<IMenuItem>, index: number) => {
const commandService: ICommandService = this.context.injector.get(ICommandService);
- const { disabled } = this.state;
+ this.props.onClick();
+
+ // TODO: type here is not correct
+ const value = this.state.value;
+ // !(item.subMenuItems && item.subMenuItems.length > 0) && commandService.executeCommand(item.id, { value });
+ };
+
+ /**
+ * user input change value from CustomLabel
+ * @param e
+ */
+ onChange = (e: Event) => {
+ const targetValue = (e.target as HTMLInputElement).value;
+ const value = isRealNum(targetValue) ? parseInt(targetValue) : targetValue;
+
+ this.setState({
+ value,
+ });
+ };
+
+ override render(): ComponentChild {
+ switch (this.props.menuItem.type) {
+ case MenuItemType.SELECTOR:
+ return this.renderSelectorType();
+ case MenuItemType.SUBITEMS:
+ return this.renderSubItemsType();
+ default:
+ return this.renderButtonType();
+ }
+ }
+
+ // button type command should directly execute command
+ private renderButtonType(): ComponentChild {
+ const { menuItem, onClick } = this.props;
+ const { disabled, value } = this.state;
+ const { injector } = this.context;
+
+ const commandService: ICommandService = injector.get(ICommandService);
+ const item = menuItem as IDisplayMenuItem<IMenuButtonItem>;
+ const { title, display, label } = item;
+
+ console.log('debug, value', value, title);
return (
<li
className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}
- // style={{ ...style }}
+ disabled={disabled}
onClick={() => {
- this.props.onClick();
commandService.executeCommand(item.id);
+ onClick();
}}
- onMouseEnter={(e) => {
- this.mouseEnter(e, index);
- }}
- onMouseLeave={(e) => {
- this.mouseLeave(e, index);
- }}
>
- <CustomLabel label={item.label || item.title}></CustomLabel>
+ <NeoCustomLabel
+ display={display}
+ value={value}
+ title={title}
+ label={label}
+ onChange={(v) => {
+ commandService.executeCommand(item.id, { value: v });
+ onClick();
+ }}
+ ></NeoCustomLabel>
+ </li>
+ );
+ }
+
+ private renderSelectorType(): ComponentChild {
+ const { menuItem, index } = this.props;
+ const { disabled, menuItems, value } = this.state;
+ const item = menuItem as IDisplayMenuItem<IMenuSelectorItem<unknown>>;
+ const commandService: ICommandService = this.context.injector.get(ICommandService);
+
+ return (
+ <li
+ className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}
+ onMouseEnter={(e) => this.mouseEnter(e, index)}
+ onMouseLeave={(e) => this.mouseLeave(e, index)}
+ onClick={(e) => this.handleClick(e, item, index)}
+ >
+ <NeoCustomLabel title={item.title} value={value} onChange={this.onChange} icon={item.icon} display={item.display} label={item.label}></NeoCustomLabel>
{item.shortcut && ` (${item.shortcut})`}
- {item.subMenuItems && item.subMenuItems.length > 0 ? (
- <Menu ref={(ele: Menu) => (this._refs[index] = ele)} menuItems={item.subMenuItems} parent={this}></Menu>
- ) : (
- <></>
+ {(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (
+ <Menu
+ ref={(ele: Menu) => (this._refs[index] = ele)}
+ onOptionSelect={(v) => commandService.executeCommand(item.id, { value: v.value })}
+ menuId={item.id}
+ options={item.selections}
+ display={item.display}
+ parent={this}
+ ></Menu>
)}
</li>
);
}
+
+ private renderSubItemsType(): ComponentChild {
+ const { menuItem, index } = this.props;
+ const { disabled, menuItems } = this.state;
+ const item = menuItem as IDisplayMenuItem<IMenuSelectorItem<unknown>>;
+
+ return (
+ <li
+ className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}
+ onMouseEnter={(e) => this.mouseEnter(e, index)}
+ onMouseLeave={(e) => this.mouseLeave(e, index)}
+ >
+ <NeoCustomLabel title={item.title} value={item.title} icon={item.icon} display={item.display} label={item.label}></NeoCustomLabel>
+ {(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (
+ <Menu ref={(ele: Menu) => (this._refs[index] = ele)} menuId={item.id} parent={this} display={item.display}></Menu>
+ )}
+ </li>
+ );
+ }
+
+ private getSubMenus() {
+ const { menuItem } = this.props;
+ const { id } = menuItem;
+
+ if (id) {
+ const menuService: IMenuService = this.context.injector.get(IMenuService);
+ this.setState({
+ menuItems: menuService.getMenuItems(id),
+ });
+ }
+ }
}
diff --git a/packages/base-ui/src/Components/Select/Select.tsx b/packages/base-ui/src/Components/Select/Select.tsx
index 57ab282bf9..886bca399c 100644
--- a/packages/base-ui/src/Components/Select/Select.tsx
+++ b/packages/base-ui/src/Components/Select/Select.tsx
@@ -1,26 +1,49 @@
import { ComponentChildren, createRef, RefObject } from 'preact';
import { PureComponent } from 'preact/compat';
-import { Icon } from '..';
-import { ICustomComponent } from '../../Common';
+import { AppContext, ICustomComponent } from '../../Common';
import { BaseMenuItem } from '../../Interfaces';
import { Dropdown } from '../Dropdown';
import { Input } from '../Input';
import { BaseItemProps, Item } from '../Item/Item';
-import { CustomLabel } from '../CustomLabel';
+import { CustomLabel, NeoCustomLabel } from '../CustomLabel';
import styles from './index.module.less';
+import { Icon, IValueOption } from '../..'; // FIXME: strange import
+
+// TODO: these type definitions should be moved out of components to menu service
export enum SelectTypes {
- SINGLE, // 普通下拉
+ /** 单选 */
+ SINGLE,
+ /** dropdown with input */
INPUT,
COLOR,
+ /** 两栏菜单,主按钮会跟着上次的选项发生变化 */
DOUBLE,
+ /** 显示一个固定的值 */
FIX,
+ /** 显示一个固定的值 */
DOUBLEFIX,
+
+ /** This should be the only type. The enum would be removed after we finish refactor. */
+ NEO,
}
-enum DisplayTypes {
+export enum DisplayTypes {
LABEL,
+
+ /** @deprecated */
SUFFIX,
+
+ ICON,
+
+ /** Label as color display. */
+ COLOR,
+
+ INPUT,
+
+ FONT,
+
+ CUSTOM,
}
export interface BaseSelectChildrenProps extends BaseItemProps {
@@ -46,20 +69,31 @@ export interface BaseSelectProps {
name?: string;
suffix?: any;
tooltip?: string;
+ value?: string | number;
+ icon?: string;
+ id?: string;
+ options?: IValueOption[];
+ title?: string;
}
interface IState {
menu: BaseMenuItem[];
- color: string;
+ color: string; // TODO@wzhudev: this state is strange
content: ComponentChildren;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
}
export class Select extends PureComponent<BaseSelectProps, IState> {
+ static override contextType = AppContext;
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
ColorRef: any;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
onClick: (...arg: any) => void;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
onPressEnter: (...arg: any[]) => void;
constructor(props: BaseSelectProps) {
@@ -81,22 +115,27 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
getType(type: SelectTypes) {
switch (type) {
- case 0:
+ case SelectTypes.SINGLE:
return this.getSingle();
- case 1:
+ case SelectTypes.INPUT:
return this.getInput();
- case 3:
+ case SelectTypes.DOUBLE:
return this.getDouble();
- case 4:
+ case SelectTypes.FIX:
return this.getFix();
- case 5:
+ case SelectTypes.DOUBLEFIX:
return this.getDoubleFix();
+ case SelectTypes.NEO:
+ return this.renderNeo();
}
}
+ // eslint-disable-next-line max-lines-per-function
initData() {
const { type, display, children = [], label } = this.props;
+ // TODO@wzhudev: the way of binding onClick is ridiculous. Fix it.
+
// 显示值可变
if (type === 0 || type === 3) {
if (!children.length) return;
@@ -221,17 +260,23 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
}
}
- componentDidMount() {
+ updateData() {
+ if (this.props.type === SelectTypes.INPUT) {
+ this.setState({ content: this.props.label });
+ }
+ }
+
+ override componentDidMount() {
this.initData();
}
- componentWillReceiveProps(nextProps: BaseSelectProps) {
- // this.props = Object.assign(this.props, nextProps);
- // this.initData();
+ override componentWillReceiveProps(nextProps: BaseSelectProps) {
+ this.updateData();
}
resetMenu(children: BaseSelectChildrenProps[], hideSelectedIcon?: boolean) {
const list: BaseMenuItem[] = [];
+ // TODO@wzhudev: ID prop is not handled
for (let i = 0; i < children.length; i++) {
let selected = false;
if (!hideSelectedIcon) {
@@ -300,7 +345,12 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
return (
<div className={`${styles.selectInput} ${className}`}>
<Dropdown onMainClick={onMainClick} ref={ref} tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
- <Input onPressEnter={(e) => this.handlePressEnter(e, ref)} onBlur={this.onPressEnter} type="number" value={content as string} />
+ <Input
+ onPressEnter={(e) => this.handlePressEnter(e, ref)}
+ onBlur={this.onPressEnter}
+ type="number"
+ value={`${this.props.label as number}` ?? (content as string)}
+ />
</Dropdown>
</div>
);
@@ -329,7 +379,7 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
<div className={`${styles.selectDouble} ${className}`}>
<Dropdown tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
<div className={styles.selectLabel}>
- <CustomLabel label={content} />
+ <CustomLabel label={label} />
</div>
</Dropdown>
</div>
@@ -337,13 +387,50 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
};
getDoubleFix = () => {
- const { label, className = '', tooltip, onClick } = this.props;
+ const { label, className = '', tooltip, onClick, display, value, icon } = this.props;
const { menu } = this.state;
+
return (
<div className={`${styles.selectDouble} ${className}`}>
<Dropdown tooltip={tooltip} onClick={onClick} menu={{ menu, onClick: this.onClick }} icon={<Icon.NextIcon />}>
<div className={styles.selectLabel}>
- <CustomLabel label={label} />
+ <CustomLabel display={display} label={label} value={`${value}`} icon={icon} />
+ </div>
+ </Dropdown>
+ </div>
+ );
+ };
+
+ renderNeo = () => {
+ const { tooltip, onClick, display, value, icon, title, id, options, type } = this.props;
+
+ const onClickInner = (...args: unknown[]) => {
+ onClick?.(args[1] as number | string);
+ };
+
+ const onOptionSelect = (option: IValueOption) => {
+ onClick?.(option.value);
+ };
+
+ const iconToDisplay = options?.find((o) => o.value === value)?.icon ?? icon;
+ const displayInSubMenu = display === DisplayTypes.ICON ? DisplayTypes.LABEL : display === DisplayTypes.INPUT ? DisplayTypes.LABEL : display;
+ return (
+ <div className={`${styles.selectDouble}`}>
+ <Dropdown
+ tooltip={tooltip}
+ onClick={type === SelectTypes.NEO ? () => onClick?.(value) : onClick}
+ menu={{
+ menuId: id,
+ options,
+ onClick: onClickInner,
+ onOptionSelect,
+ value,
+ display: displayInSubMenu,
+ }}
+ icon={<Icon.NextIcon />}
+ >
+ <div className={styles.selectLabel}>
+ <NeoCustomLabel icon={iconToDisplay} display={display} title={title!} value={value} onChange={(v) => onClick?.(v)} />
</div>
</Dropdown>
</div>
diff --git a/packages/base-ui/src/Interfaces/CustomLabel.ts b/packages/base-ui/src/Interfaces/CustomLabel.ts
index 91443f1eaf..34b293b9f3 100644
--- a/packages/base-ui/src/Interfaces/CustomLabel.ts
+++ b/packages/base-ui/src/Interfaces/CustomLabel.ts
@@ -1,7 +1,7 @@
import { ComponentChildren } from 'preact';
import { BaseComponent, JSXComponent } from '../BaseComponent';
import { ICustomComponent } from '../Common';
-import { BaseSelectChildrenProps } from '../Components/Select/Select';
+import { BaseSelectChildrenProps, DisplayTypes } from '../Components/Select/Select';
export interface ICustomLabelProps {
prefix?: string[] | string;
@@ -18,7 +18,11 @@ export interface ICustomLabelType {
}
export interface IBaseCustomLabelProps {
+ icon?: string;
+ value?: string;
label: string | ICustomComponent | ComponentChildren;
+ display?: DisplayTypes;
+ onChange?: (e: Event) => void;
}
export interface CustomLabelComponent extends BaseComponent<IBaseCustomLabelProps> {
diff --git a/packages/base-ui/src/Interfaces/Dropdown.ts b/packages/base-ui/src/Interfaces/Dropdown.ts
index 5e37eb6de8..4fd0d1f657 100644
--- a/packages/base-ui/src/Interfaces/Dropdown.ts
+++ b/packages/base-ui/src/Interfaces/Dropdown.ts
@@ -4,6 +4,7 @@ import { BaseMenuProps } from './Menu';
export interface BaseDropdownProps {
children: ComponentChildren;
+ /** @deprecated dropdown shouldn't know what is inside */
menu: BaseMenuProps;
placement?: 'Left' | 'Right' | 'Top' | 'Bottom';
showArrow?: boolean;
@@ -11,6 +12,7 @@ export interface BaseDropdownProps {
onClick?: () => void;
onMainClick?: () => void; //非功能按钮事件
tooltip?: string;
+ content?: ComponentChildren;
}
export interface DropdownComponent extends BaseComponent<BaseDropdownProps> {
diff --git a/packages/base-ui/src/Interfaces/Input.ts b/packages/base-ui/src/Interfaces/Input.ts
index 775bbdd170..5a34b012ef 100644
--- a/packages/base-ui/src/Interfaces/Input.ts
+++ b/packages/base-ui/src/Interfaces/Input.ts
@@ -14,6 +14,7 @@ export interface BaseInputProps extends BaseComponentProps {
onFocus?: (e: Event) => void;
onBlur?: (e: FocusEvent) => void;
onClick?: (e: MouseEvent) => void;
+ onValueChange?: (value: string) => void;
className?: string;
readonly?: boolean;
id?: string;
diff --git a/packages/base-ui/src/Interfaces/Menu.ts b/packages/base-ui/src/Interfaces/Menu.ts
index 2880b2bdcb..d7241da82a 100644
--- a/packages/base-ui/src/Interfaces/Menu.ts
+++ b/packages/base-ui/src/Interfaces/Menu.ts
@@ -1,6 +1,7 @@
import { ComponentChildren, JSX } from 'preact';
import { BaseComponent, JSXComponent } from '../BaseComponent';
-import { IDisplayMenuItem, IMenuItem } from '../services/menu/menu.service';
+import { ICustomComponentOption, IValueOption } from '../services/menu/menu';
+import { DisplayTypes } from '../Components/Select/Select';
export interface BaseMenuItem {
className?: string;
@@ -15,20 +16,30 @@ export interface BaseMenuItem {
}
export interface BaseMenuProps {
- /** @deprecated this is legacy menu mechanism. Do not use it. Use `menuItems` instead. */
- menu?: BaseMenuItem[];
- menuItems?: IDisplayMenuItem[];
+ /** @deprecated */
onClick?: (...arg: any) => void;
+ /** @deprecated */
className?: string;
+ /** @deprecated */
style?: JSX.CSSProperties;
+ /** @deprecated */
parent?: any;
+ /** @deprecated */
dom?: HTMLElement;
+ /** @deprecated */
ref?: any;
+ /** @deprecated */
deep?: number;
-}
+ /** @deprecated this is legacy menu mechanism. Do not use it. Use `menuItems` instead. */
+ menu?: BaseMenuItem[]; // TODO: should be renamed to `items`
+
+ // NOTE: options above are legacy. They are going to be removed after we complete refactoring.
-export interface TreeMenuItems extends IMenuItem {
- subMenuItems: TreeMenuItems[];
+ display?: DisplayTypes;
+ menuId?: string;
+ value?: string | number;
+ options?: Array<IValueOption | ICustomComponentOption>;
+ onOptionSelect?: (option: IValueOption) => void;
}
export type BaseMenuState = {
diff --git a/packages/base-ui/src/Interfaces/Tooltip.ts b/packages/base-ui/src/Interfaces/Tooltip.ts
index 4ba8d529b8..49029302e0 100644
--- a/packages/base-ui/src/Interfaces/Tooltip.ts
+++ b/packages/base-ui/src/Interfaces/Tooltip.ts
@@ -3,7 +3,9 @@ import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponen
export interface BaseTooltipProps extends BaseComponentProps {
[index: number]: string;
+
title?: string;
+ shortcut?: string;
children: ComponentChildren;
placement?: string;
color?: string;
diff --git a/packages/base-ui/src/controllers/shared-shortcut.controller.ts b/packages/base-ui/src/controllers/shared-shortcut.controller.ts
index f7315afb7e..b3fc46400b 100644
--- a/packages/base-ui/src/controllers/shared-shortcut.controller.ts
+++ b/packages/base-ui/src/controllers/shared-shortcut.controller.ts
@@ -1,6 +1,6 @@
import { Disposable, ICommandService, RedoCommand, UndoCommand } from '@univerjs/core';
-import { IShortcutItem, IShortcutService } from '../services/shortcut/shorcut.service';
+import { IShortcutItem, IShortcutService } from '../services/shortcut/shortcut.service';
import { KeyCode, MetaKeys } from '../services/shortcut/keycode';
export const UndoShortcutItem: IShortcutItem = {
@@ -23,11 +23,11 @@ export class SharedController extends Disposable {
this.registerShortcuts();
}
- private registerToolbarItem(): void {}
+ // private registerToolbarItem(): void {}
- private registerContextMenuItem(): void {}
+ // private registerContextMenuItem(): void {}
- private registerFooterItem(): void {}
+ // private registerFooterItem(): void {}
private registerShortcuts(): void {
[UndoShortcutItem, RedoShortcutItem].forEach((shortcut) => {
diff --git a/packages/base-ui/src/index.ts b/packages/base-ui/src/index.ts
index f05aa731de..c040a6a5de 100644
--- a/packages/base-ui/src/index.ts
+++ b/packages/base-ui/src/index.ts
@@ -8,9 +8,22 @@ export * from './Components';
export * from './BaseComponent';
export * from './UIPlugin';
-export { IMenuService, IMenuItem, MenuPosition, DesktopMenuService, IDisplayMenuItem } from './services/menu/menu.service';
+export {
+ ICustomComponentProps,
+ ICustomComponentOption,
+ IMenuButtonItem,
+ IMenuItem,
+ IMenuSelectorItem,
+ IValueOption,
+ MenuItemType,
+ MenuPosition,
+ IDisplayMenuItem,
+ isCustomComponentOption,
+ isValueOptions,
+} from './services/menu/menu';
+export { IMenuService, DesktopMenuService } from './services/menu/menu.service';
export { KeyCode, MetaKeys } from './services/shortcut/keycode';
-export { IShortcutService, IShortcutItem, DesktopShortcutService } from './services/shortcut/shorcut.service';
+export { IShortcutService, IShortcutItem, DesktopShortcutService } from './services/shortcut/shortcut.service';
export { IPlatformService, DesktopPlatformService } from './services/platform/platform.service';
export { SharedController } from './controllers/shared-shortcut.controller';
diff --git a/packages/base-ui/src/services/menu/menu.service.ts b/packages/base-ui/src/services/menu/menu.service.ts
index cc25c47797..2712b8dbb9 100644
--- a/packages/base-ui/src/services/menu/menu.service.ts
+++ b/packages/base-ui/src/services/menu/menu.service.ts
@@ -1,17 +1,9 @@
+import { IDisposable, createIdentifier } from '@wendellhu/redi';
import { Disposable, toDisposable } from '@univerjs/core';
-import { createIdentifier, IDisposable } from '@wendellhu/redi';
-import { Observable } from 'rxjs';
-import { ComponentChildren } from 'preact';
-import { IShortcutService } from '../shortcut/shorcut.service';
-import { ICustomLabelType } from '../../Interfaces/CustomLabel';
+import { IShortcutService } from '../shortcut/shortcut.service';
import { BaseSelectChildrenProps } from '../../Components/Select/Select';
-export type OneOrMany<T> = T | T[];
-
-export const enum MenuPosition {
- TOOLBAR,
- CONTEXT_MENU,
-}
+import { IDisplayMenuItem, IMenuItem, MenuPosition } from './menu';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface IMenuItemState {
@@ -38,42 +30,20 @@ export interface CustomLabel {
props?: CustomLabelProps;
}
-export interface IMenuItem {
- id: string;
- menu: OneOrMany<MenuPosition>;
- subMenus?: string[]; // submenu id list
- parentId?: string; // if it is submenu
- label?: string | ICustomLabelType | ComponentChildren;
-
- title: string;
- icon?: string;
- tooltip?: string;
- description?: string;
-
- hidden$?: Observable<boolean>;
- activated$?: Observable<boolean>;
- disabled$?: Observable<boolean>;
-}
-
-export interface IDisplayMenuItem extends IMenuItem {
- /** MenuService should get responsible shortcut and display on the UI. */
- shortcut?: string;
- subMenuItems?: IDisplayMenuItem[];
-}
-
export const IMenuService = createIdentifier<IMenuService>('univer.menu-service');
export interface IMenuService {
addMenuItem(item: IMenuItem): IDisposable;
- /** Get menu items at a given position. */
- getMenuItems(position: MenuPosition): IMenuItem[];
+
+ /** Get menu items for display at a given position or a submenu. */
+ getMenuItems(position: MenuPosition | string): Array<IDisplayMenuItem<IMenuItem>>;
getMenuItem(id: string): IMenuItem | null;
}
export class DesktopMenuService extends Disposable implements IMenuService {
private readonly _menuItemMap = new Map<string, IMenuItem>();
- private readonly _menuByPositions = new Map<MenuPosition, Map<string, IMenuItem>>();
+ private readonly _menuByPositions = new Map<MenuPosition | string, Array<[string, IMenuItem]>>();
constructor(@IShortcutService private readonly _shortcutService: IShortcutService) {
super();
@@ -89,29 +59,49 @@ export class DesktopMenuService extends Disposable implements IMenuService {
}
this._menuItemMap.set(item.id, item);
- if (Array.isArray(item.menu)) {
- item.menu.forEach((menu) => this.appendMenuToPosition(item, menu));
+
+ if (Array.isArray(item.positions)) {
+ item.positions.forEach((menu) => this.appendMenuToPosition(item, menu));
} else {
- this.appendMenuToPosition(item, item.menu);
+ this.appendMenuToPosition(item, item.positions);
}
return toDisposable(() => {
this._menuItemMap.delete(item.id);
- if (Array.isArray(item.menu)) {
- item.menu.forEach((menu) => this._menuByPositions.get(menu)?.delete(item.id));
+
+ if (Array.isArray(item.positions)) {
+ item.positions.forEach((menu) => {
+ const menus = this._menuByPositions.get(menu);
+ if (!menus) {
+ return;
+ }
+
+ const index = menus.findIndex((m) => m[0] === item.id);
+ if (index > -1) {
+ menus.splice(index, 1);
+ }
+ });
} else {
- this._menuByPositions.get(item.menu)?.delete(item.id);
+ const menus = this._menuByPositions.get(item.positions);
+ if (!menus) {
+ return;
+ }
+
+ const index = menus.findIndex((m) => m[0] === item.id);
+ if (index > -1) {
+ menus.splice(index, 1);
+ }
}
});
}
- getMenuItems(positions: MenuPosition): IDisplayMenuItem[] {
+ getMenuItems(positions: MenuPosition | string): Array<IDisplayMenuItem<IMenuItem>> {
// TODO: @wzhudev: compose shortcut to returned menu items.
if (this._menuByPositions.has(positions)) {
- return [...this._menuByPositions.get(positions)!.values()].map((menu) => this.getDisplayMenuItems(menu));
+ return [...this._menuByPositions.get(positions)!.values()].map((menu) => this.getDisplayMenuItems(menu[1]));
}
- return [] as IDisplayMenuItem[];
+ return [] as Array<IDisplayMenuItem<IMenuItem>>;
}
getMenuItem(id: string): IMenuItem | null {
@@ -122,7 +112,7 @@ export class DesktopMenuService extends Disposable implements IMenuService {
return null;
}
- private getDisplayMenuItems(menuItem: IMenuItem): IDisplayMenuItem {
+ private getDisplayMenuItems(menuItem: IMenuItem): IDisplayMenuItem<IMenuItem> {
const shortcut = this._shortcutService.getCommandShortcut(menuItem.id);
if (!shortcut) {
return menuItem;
@@ -134,16 +124,16 @@ export class DesktopMenuService extends Disposable implements IMenuService {
};
}
- private appendMenuToPosition(menu: IMenuItem, position: MenuPosition) {
+ private appendMenuToPosition(menu: IMenuItem, position: MenuPosition | string) {
if (!this._menuByPositions.has(position)) {
- this._menuByPositions.set(position, new Map<string, IMenuItem>());
+ this._menuByPositions.set(position, []);
}
- const menuSet = this._menuByPositions.get(position)!;
- if (menuSet.has(menu.id)) {
+ const menuList = this._menuByPositions.get(position)!;
+ if (menuList.findIndex((m) => m[0] === menu.id) > -1) {
throw new Error(`Menu item with the same id ${menu.id} has already been added!`);
}
- menuSet.set(menu.id, menu);
+ menuList.push([menu.id, menu]);
}
}
diff --git a/packages/base-ui/src/services/menu/menu.ts b/packages/base-ui/src/services/menu/menu.ts
new file mode 100644
index 0000000000..712c4b282d
--- /dev/null
+++ b/packages/base-ui/src/services/menu/menu.ts
@@ -0,0 +1,122 @@
+import { Observable } from 'rxjs';
+
+import { IAccessor } from '@wendellhu/redi';
+import { DisplayTypes, SelectTypes } from '../../Components/Select/Select';
+
+export type OneOrMany<T> = T | T[];
+
+export const enum MenuPosition {
+ VOID = 'void',
+ TOOLBAR = 'toolbar',
+ CONTEXT_MENU = 'contextMenu',
+ TAB_CONTEXT_MENU = 'tabContextMenu',
+ ROW_HEADER_CONTEXT_MENU = 'rowHeaderContextMenu',
+ COL_HEADER_CONTEXT_MENU = 'colHeaderContextMenu',
+ SHEET_BAR = 'sheetBar',
+}
+
+export const enum MenuItemType {
+ /** Button style menu item. */
+ BUTTON,
+ /** Menu item with submenus. Submenus could be other IMenuItem or an ID of a registered component. */
+ SELECTOR,
+ /** Submenus have to specific features and do not invoke commands. */
+ SUBITEMS,
+}
+
+interface IMenuItemBase<V> {
+ /** ID of the menu item. Normally it should be the same as the ID of the command that it would invoke. */
+ id: string;
+ title: string;
+ description?: string;
+ icon?: string;
+ tooltip?: string;
+
+ /** In what menu should the item display. */
+ positions: OneOrMany<MenuPosition | string>;
+
+ /** @deprecated this type seems unnecessary */
+ type: MenuItemType;
+ /** Determines how the label of the selector should display. */
+ display?: DisplayTypes;
+ /**
+ * Custom label component id.
+ * */
+ label?:
+ | string
+ | {
+ name: string;
+ props?: Record<string, string | number>;
+ };
+
+ hidden$?: Observable<boolean>;
+ disabled$?: Observable<boolean>;
+ /** On observable value that should emit the value of the corresponding selection component. */
+ value$?: Observable<V>;
+}
+
+export interface IMenuButtonItem<V = undefined> extends IMenuItemBase<V> {
+ type: MenuItemType.BUTTON;
+
+ activated$?: Observable<boolean>;
+
+ // TODO@wzhudev: I may deprecate this
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ onClick?: (...arg: any) => void; // menu button click callback, does not trigger command. e.g. sheet bar rename
+}
+
+export function isMenuButtonItem(v: IMenuItem): v is IMenuButtonItem {
+ return v.type === MenuItemType.BUTTON;
+}
+
+export interface IValueOption {
+ value: string | number;
+ label: string;
+ icon?: string;
+ tooltip?: string;
+ style?: object;
+ disabled?: boolean;
+}
+
+export function isValueOptions(v: IValueOption | ICustomComponentOption): v is IValueOption {
+ return typeof (v as IValueOption).value !== 'undefined';
+}
+
+export interface ICustomComponentOption {
+ id: string;
+}
+
+export interface ICustomComponentProps<T> {
+ value: T;
+ onChange: (v: T) => void;
+}
+
+export function isCustomComponentOption(v: IValueOption | ICustomComponentOption): v is ICustomComponentOption {
+ return typeof (v as ICustomComponentOption).id !== 'undefined';
+}
+
+export interface IMenuSelectorItem<V> extends IMenuItemBase<V> {
+ type: MenuItemType.SELECTOR | MenuItemType.SUBITEMS;
+
+ /** @deprecated this parameter would be removed after we complete refactoring, because they will be all NEO */
+ selectType: SelectTypes;
+
+ // selections 子菜单可以为三种类型
+ // 一个是当前 menu 的 options,选中后直接使用其 value 触发 command
+ // 一个是一个特殊组件,比如 color picker,选中后直接使用其 value 触发 command
+ // 一个是其他 menu 的 id,直接渲染成其他的 menu
+ /** Options or IDs of registered components. */
+ selections?: Array<IValueOption | ICustomComponentOption>;
+}
+
+export function isMenuSelectorItem<T>(v: IMenuItem): v is IMenuSelectorItem<T> {
+ return v.type === MenuItemType.SELECTOR || v.type === MenuItemType.SUBITEMS;
+}
+
+export type IMenuItem = IMenuButtonItem | IMenuSelectorItem<unknown>;
+
+export type IDisplayMenuItem<T extends IMenuItem> = T & {
+ shortcut?: string;
+};
+
+export type IMenuItemFactory = (accessor: IAccessor) => IMenuItem;
diff --git a/packages/base-ui/src/services/shortcut/shorcut.service.ts b/packages/base-ui/src/services/shortcut/shortcut.service.ts
similarity index 98%
rename from packages/base-ui/src/services/shortcut/shorcut.service.ts
rename to packages/base-ui/src/services/shortcut/shortcut.service.ts
index fb71a5acae..6ddc363ef6 100644
--- a/packages/base-ui/src/services/shortcut/shorcut.service.ts
+++ b/packages/base-ui/src/services/shortcut/shortcut.service.ts
@@ -10,6 +10,8 @@ export interface IShortcutItem<P extends object = object> {
id: string;
description?: string;
+ // TODO@wzhudev: add a precondition to check if the command should trigger
+
/** A command can be bound to several bindings, with different static parameters perhaps. */
binding: number;
mac?: number;
diff --git a/packages/core/package.json b/packages/core/package.json
index fa487b8ee2..b5725f990d 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -53,7 +53,7 @@
"url": "https://github.com/dream-num/univer.git"
},
"dependencies": {
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"dayjs": "^1.11.5",
"es6-proxy-polyfill": "^2.1.1",
"nanoid": "4.0.0",
diff --git a/packages/core/src/Shared/Generate.ts b/packages/core/src/Shared/Generate.ts
index aff3041ee0..a0bdb0c2b9 100644
--- a/packages/core/src/Shared/Generate.ts
+++ b/packages/core/src/Shared/Generate.ts
@@ -26,7 +26,7 @@ function valueIsError(value: string) {
}
// 是否是纯数字
-function isRealNum(val: string | number) {
+export function isRealNum(val: string | number) {
if (val === null || val.toString().replace(/\s/g, '') === '') {
return false;
}
@@ -35,7 +35,7 @@ function isRealNum(val: string | number) {
return false;
}
- if (!Number.isNaN(val as number)) {
+ if (!isNaN(val as number)) {
return true;
}
return false;
diff --git a/packages/core/src/Sheets/Domain/Range.ts b/packages/core/src/Sheets/Domain/Range.ts
index 784fdf7604..daf191040a 100644
--- a/packages/core/src/Sheets/Domain/Range.ts
+++ b/packages/core/src/Sheets/Domain/Range.ts
@@ -677,7 +677,7 @@ export class Range {
* Returns the text rotation settings for the top left cell of the range.
*/
// getTextRotation(): number {
- getTextRotation() {
+ getTextRotation(): number {
return this.getTextRotations()[0][0];
}
@@ -685,8 +685,8 @@ export class Range {
* Returns the text rotation settings for the cells in the range.
*/
// getTextRotations(): number[][] {
- getTextRotations() {
- return this._getStyles('tr');
+ getTextRotations(): number[][] {
+ return this._getStyles('tr') as any as number[][]; // FIXME@Dushusir: fix type
}
/**
diff --git a/packages/core/src/Types/Interfaces/IStyleData.ts b/packages/core/src/Types/Interfaces/IStyleData.ts
index c28c9069c0..7705682692 100644
--- a/packages/core/src/Types/Interfaces/IStyleData.ts
+++ b/packages/core/src/Types/Interfaces/IStyleData.ts
@@ -1,13 +1,5 @@
import { BorderStyleTypes } from '../Enum/BorderStyleTypes';
-import {
- BooleanNumber,
- HorizontalAlign,
- TextDecoration,
- TextDirection,
- BaselineOffset,
- VerticalAlign,
- WrapStrategy,
-} from '../Enum/TextStyle';
+import { BooleanNumber, HorizontalAlign, TextDecoration, TextDirection, BaselineOffset, VerticalAlign, WrapStrategy } from '../Enum/TextStyle';
import { ThemeColorType } from '../Enum/ThemeColorType';
import { Nullable } from '../../Shared/Types';
diff --git a/packages/sheets-plugin-find/package.json b/packages/sheets-plugin-find/package.json
index 23ae8367cf..0c3af5c287 100644
--- a/packages/sheets-plugin-find/package.json
+++ b/packages/sheets-plugin-find/package.json
@@ -57,6 +57,6 @@
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
"preact": "^10.12.1",
- "@wendellhu/redi": "^0.12.6"
+ "@wendellhu/redi": "^0.12.7"
}
}
diff --git a/packages/sheets-plugin-formula/package.json b/packages/sheets-plugin-formula/package.json
index 9af7c18280..c25b6ae877 100644
--- a/packages/sheets-plugin-formula/package.json
+++ b/packages/sheets-plugin-formula/package.json
@@ -56,7 +56,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"preact": "^10.12.1"
}
}
diff --git a/packages/sheets-plugin-image/package.json b/packages/sheets-plugin-image/package.json
index f25619c40c..e38ee139fa 100644
--- a/packages/sheets-plugin-image/package.json
+++ b/packages/sheets-plugin-image/package.json
@@ -56,7 +56,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.12.6",
+ "@wendellhu/redi": "^0.12.7",
"preact": "^10.12.1"
}
}
\ No newline at end of file
diff --git a/packages/sheets-plugin-import-xlsx/package.json b/packages/sheets-plugin-import-xlsx/package.json
index eb44ef582d..1459193086 100644
--- a/packages/sheets-plugin-import-xlsx/package.json
+++ b/packages/sheets-plugin-import-xlsx/package.json
@@ -53,7 +53,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"luckyexcel": "^1.0.1",
"preact": "^10.12.1"
}
diff --git a/packages/sheets-plugin-numfmt/package.json b/packages/sheets-plugin-numfmt/package.json
index e372beb548..2cb4613d28 100644
--- a/packages/sheets-plugin-numfmt/package.json
+++ b/packages/sheets-plugin-numfmt/package.json
@@ -63,7 +63,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"preact": "^10.12.1"
}
}
\ No newline at end of file
diff --git a/packages/sheets-plugin-operation/package.json b/packages/sheets-plugin-operation/package.json
index 10df7feec4..36145567a9 100644
--- a/packages/sheets-plugin-operation/package.json
+++ b/packages/sheets-plugin-operation/package.json
@@ -53,6 +53,6 @@
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
"preact": "^10.12.1",
- "@wendellhu/redi": "^0.12.6"
+ "@wendellhu/redi": "^0.12.7"
}
}
diff --git a/packages/ui-plugin-docs/package.json b/packages/ui-plugin-docs/package.json
index d8c4374698..af86039bc4 100644
--- a/packages/ui-plugin-docs/package.json
+++ b/packages/ui-plugin-docs/package.json
@@ -57,7 +57,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/base-docs": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1"
}
diff --git a/packages/ui-plugin-sheets/package.json b/packages/ui-plugin-sheets/package.json
index 8241c0c22a..e7a598a552 100644
--- a/packages/ui-plugin-sheets/package.json
+++ b/packages/ui-plugin-sheets/package.json
@@ -55,7 +55,7 @@
"@univerjs/base-sheets": "workspace:^0.0.1",
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.6",
+ "@wendellhu/redi": "^0.12.7",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1",
"rxjs": "^7.8.1"
diff --git a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
index 3f608922c3..c8a90e6aec 100644
--- a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
@@ -4,6 +4,7 @@ import { ComponentChildren } from 'preact';
import { Disposable, ICurrentUniverService, ObserverManager, Tools, UIObserver } from '@univerjs/core';
import { Inject, Injector, SkipSelf } from '@wendellhu/redi';
import { CanvasView } from '@univerjs/base-sheets';
+import { IMenuItemFactory } from '@univerjs/base-ui/src/services/menu/menu';
import { DefaultRightMenuConfig, SheetRightMenuConfig } from '../Basics';
import { RightMenu, RightMenuInput, RightMenuItem } from '../View';
import styles from '../View/RightMenu/index.module.less';
@@ -304,18 +305,20 @@ export class RightMenuUIController extends Disposable {
}
private _initializeContextMenu() {
- [
- ClearSelectionMenuItemFactory,
- InsertRowMenuItemFactory,
- InsertColMenuItemFactory,
- RemoveRowMenuItemFactory,
- RemoveColMenuItemFactory,
- SetRowHeightMenuItemFactory,
- SetColWidthMenuItemFactory,
- DeleteRangeMenuItemFactory,
- DeleteRangeMoveLeftMenuItemFactory,
- DeleteRangeMoveUpMenuItemFactory,
- ].forEach((factory) => {
+ (
+ [
+ ClearSelectionMenuItemFactory,
+ InsertRowMenuItemFactory,
+ InsertColMenuItemFactory,
+ RemoveRowMenuItemFactory,
+ RemoveColMenuItemFactory,
+ SetRowHeightMenuItemFactory,
+ SetColWidthMenuItemFactory,
+ DeleteRangeMenuItemFactory,
+ DeleteRangeMoveLeftMenuItemFactory,
+ DeleteRangeMoveUpMenuItemFactory,
+ ] as IMenuItemFactory[]
+ ).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
});
}
diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
index 49397fcbe6..ec6fb0c9e2 100644
--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
@@ -1,4 +1,4 @@
-import { BaseMenuItem, BaseUlProps, ColorPicker, ComponentManager, ICustomComponent } from '@univerjs/base-ui';
+import { BaseMenuItem, BaseUlProps, ColorPicker, ComponentManager, ICustomComponent, IMenuService, MenuPosition } from '@univerjs/base-ui';
import {
Nullable,
CommandManager,
@@ -18,11 +18,12 @@ import {
ICommandService,
} from '@univerjs/core';
import { InsertSheetMutation, RemoveSheetMutation, SetWorksheetActivateCommand, SetWorksheetOrderCommand } from '@univerjs/base-sheets';
-import { Inject, SkipSelf } from '@wendellhu/redi';
+import { Inject, Injector, SkipSelf } from '@wendellhu/redi';
import { SheetBar } from '../View/SheetBar';
import styles from '../View/SheetBar/index.module.less';
import { SheetBarMenuItem } from '../View/SheetBar/SheetBarMenu';
import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const';
+import { ChangeColorSheetMenuItemFactory, CopySheetMenuItemFactory, DeleteSheetMenuItemFactory, HideSheetMenuItemFactory, RenameSheetMenuItemFactory, UnHideSheetMenuItemFactory } from './menu';
interface SheetUl extends BaseMenuItem {
label?: ICustomComponent | string;
@@ -50,10 +51,12 @@ export class SheetBarUIController extends Disposable {
// eslint-disable-next-line max-lines-per-function
constructor(
+ @Inject(Injector) private readonly _injector: Injector,
@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@SkipSelf() @Inject(ObserverManager) private readonly _observerManager: ObserverManager,
- @ICommandService private readonly _commandService: ICommandService
+ @ICommandService private readonly _commandService: ICommandService,
+ @IMenuService private readonly _menuService: IMenuService
) {
super();
const that = this;
@@ -115,6 +118,8 @@ export class SheetBarUIController extends Disposable {
},
];
+ this._initializeContextMenu();
+
this._componentManager.register(SHEET_UI_PLUGIN_NAME + ColorPicker.name, ColorPicker);
this.disposeWithMe(
@@ -291,6 +296,8 @@ export class SheetBarUIController extends Disposable {
//this._barControl.dragEnd(elements);
},
});
+
+ // this._sheetBar.setSheetUlNeo(this._menuService.getMenuItems(MenuPosition.SHEET_BAR));
}
protected _refreshSheetData(): void {
@@ -349,4 +356,17 @@ export class SheetBarUIController extends Disposable {
this._refreshSheetData();
this._refreshSheetBarUI();
}
+
+ private _initializeContextMenu() {
+ [
+ DeleteSheetMenuItemFactory,
+ CopySheetMenuItemFactory,
+ RenameSheetMenuItemFactory,
+ ChangeColorSheetMenuItemFactory,
+ HideSheetMenuItemFactory,
+ UnHideSheetMenuItemFactory,
+ ].forEach((factory) => {
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
+ });
+ }
}
diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
index 5c9486c8f0..cfbff1003d 100644
--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
@@ -1,41 +1,32 @@
import { Inject, Injector, SkipSelf } from '@wendellhu/redi';
-import { BorderInfo, ISelectionManager, SelectionManager } from '@univerjs/base-sheets';
-import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager, ICustomComponent, IMenuService, MenuPosition } from '@univerjs/base-ui';
-import {
- BorderType,
- CommandManager,
- DEFAULT_STYLES,
- HorizontalAlign,
- IKeyValue,
- ISheetActionData,
- SheetActionBase,
- Tools,
- UIObserver,
- VerticalAlign,
- WrapStrategy,
- Range,
- ITextRotation,
- ICurrentUniverService,
- ObserverManager,
- Disposable,
-} from '@univerjs/core';
+import { ISelectionManager, SelectionManager } from '@univerjs/base-sheets';
+import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager, IMenuService, MenuPosition } from '@univerjs/base-ui';
+import { UIObserver, ICurrentUniverService, ObserverManager, Disposable } from '@univerjs/core';
import { ComponentChildren } from 'preact';
-import { DefaultToolbarConfig, SheetToolbarConfig, SHEET_UI_PLUGIN_NAME } from '../Basics';
+import { IMenuItemFactory } from '@univerjs/base-ui/src/services/menu/menu';
+import { SheetToolbarConfig, SHEET_UI_PLUGIN_NAME } from '../Basics';
import { ColorSelect, LineBold, LineColor, Toolbar } from '../View';
import {
- FONT_FAMILY_CHILDREN,
- FONT_SIZE_CHILDREN,
- BORDER_LINE_CHILDREN,
- BORDER_SIZE_CHILDREN,
- MERGE_CHILDREN,
- HORIZONTAL_ALIGN_CHILDREN,
- VERTICAL_ALIGN_CHILDREN,
- TEXT_WRAP_CHILDREN,
- TEXT_ROTATE_CHILDREN,
-} from '../View/Toolbar/Const';
-
-import styles from '../View/Toolbar/index.module.less';
-import { BoldMenuItemFactory, ItalicMenuItemFactory, RedoMenuItemFactory, StrikeThroughMenuItemFactory, UnderlineMenuItemFactory, UndoMenuItemFactory } from './menu';
+ UndoMenuItemFactory,
+ RedoMenuItemFactory,
+ BoldMenuItemFactory,
+ ItalicMenuItemFactory,
+ UnderlineMenuItemFactory,
+ StrikeThroughMenuItemFactory,
+ FontFamilySelectorMenuItemFactory,
+ FontSizeSelectorMenuItemFactory,
+ ResetTextColorMenuItemFactory,
+ TextColorSelectorMenuItemFactory,
+ BackgroundColorSelectorMenuItemFactory,
+ ResetBackgroundColorMenuItemFactory,
+ SetBorderColorMenuItemFactory,
+ SetBorderStyleMenuItemFactory,
+ HorizontalAlignMenuItemFactory,
+ VerticalAlignMenuItemFactory,
+ WrapTextMenuItemFactory,
+ TextRotateMenuItemFactory,
+} from './menu';
+import { CellBorderSelectorMenuItemFactory } from './menu/border.menu';
export interface BaseToolbarSelectProps extends BaseSelectProps {
children?: BaseSelectChildrenProps[];
@@ -62,29 +53,8 @@ export class ToolbarUIController extends Disposable {
/**
* @deprecated
*/
- private _toolList: IToolbarItemProps[];
-
- private _config: SheetToolbarConfig;
-
- private _lineColor: LineColor;
-
- private _lineBold: LineBold;
-
- private _colorSelect1: ColorSelect;
-
- private _textColor: string = '#000';
-
- private _colorSelect2: ColorSelect;
+ private _toolList: IToolbarItemProps[] = [];
- private _background: string = '#fff';
-
- private _borderInfo: BorderInfo = {
- type: BorderType.ALL,
- color: '#000',
- style: 1,
- }; //存储边框信息
-
- // eslint-disable-next-line max-lines-per-function
constructor(
config: SheetToolbarConfig | undefined,
@Inject(Injector) private readonly _injector: Injector,
@@ -96,277 +66,7 @@ export class ToolbarUIController extends Disposable {
) {
super();
- this._config = Tools.deepMerge({}, DefaultToolbarConfig, config);
-
- // TODO: @wzhudev: toolbar configurations should be moved to command system
- this._toolList = [
- {
- type: 0,
- tooltip: 'toolbar.font',
- className: styles.selectLabelString,
- name: 'font',
- show: this._config.font,
- border: true,
- onMainClick: () => {
- this.hideTooltip();
- },
- onClick: (fontFamily: string) => {
- this.setFontFamily(fontFamily);
- },
- children: FONT_FAMILY_CHILDREN,
- },
- {
- type: 1,
- tooltip: 'toolbar.fontSize',
- label: String(DEFAULT_STYLES.fs),
- name: 'fontSize',
- show: this._config.fontSize,
- onClick: (fontSize: number) => {
- this.setFontSize(fontSize);
- },
- onMainClick: () => {
- this.hideTooltip();
- },
- onPressEnter: (fontSize: number) => {
- this.setFontSize(fontSize);
- this.hideTooltip();
- },
- children: FONT_SIZE_CHILDREN,
- },
-
- {
- type: 5,
- tooltip: 'toolbar.textColor.main',
- label: {
- name: SHEET_UI_PLUGIN_NAME + ColorSelect.name,
- props: {
- getComponent: (ref: ColorSelect) => {
- this._colorSelect1 = ref;
- },
- color: '#000',
- label: {
- name: 'TextColorIcon',
- },
- },
- },
- onClick: () => {
- this.hideTooltip();
- const textColor = this._toolList.find((item) => item.name === 'textColor');
- if (!textColor || !textColor.label) return;
- if (!(textColor.label as ICustomComponent).props?.color) return;
- (textColor.label as ICustomComponent).props!.color = this._textColor;
- this.changeColor(this._textColor);
- },
- hideSelectedIcon: true,
- className: styles.selectColorPickerParent,
- children: [
- {
- label: 'toolbar.resetColor',
- },
- {
- label: {
- name: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
- props: {
- onClick: (color: string, e: MouseEvent) => {
- this._colorSelect1.setColor(color);
- this._textColor = color;
- },
- },
- },
- className: styles.selectColorPicker,
- },
- ],
- name: 'textColor',
- show: this._config.textColor,
- },
- {
- type: 5,
- tooltip: 'toolbar.fillColor.main',
- label: {
- name: SHEET_UI_PLUGIN_NAME + ColorSelect.name,
- props: {
- getComponent: (ref: ColorSelect) => {
- this._colorSelect2 = ref;
- },
- color: '#fff',
- label: {
- name: 'FillColorIcon',
- },
- },
- },
- onClick: () => {
- this.hideTooltip();
- const fillColor = this._toolList.find((item) => item.name === 'fillColor');
- if (!fillColor || !fillColor.label) return;
- if (!(fillColor.label as ICustomComponent).props?.color) return;
- (fillColor.label as ICustomComponent).props!.color = this._background;
- this.setBackground(this._background);
- },
- hideSelectedIcon: true,
- className: styles.selectColorPickerParent,
- children: [
- {
- label: 'toolbar.resetColor',
- },
- {
- label: {
- name: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
- props: {
- onClick: (color: string, e: MouseEvent) => {
- this._colorSelect2.setColor(color);
- this._background = color;
- },
- },
- },
- className: styles.selectColorPicker,
- },
- ],
- name: 'fillColor',
- show: this._config.fillColor,
- },
- {
- type: 3,
- display: 1,
- show: this._config.border,
- tooltip: 'toolbar.border.main',
- className: styles.selectDoubleString,
- onClick: (value: string) => {
- if (value) {
- this._borderInfo.type = value as BorderType;
- }
- this.hideTooltip();
- this.setBorder();
- },
- name: 'border',
- children: [
- ...BORDER_LINE_CHILDREN,
- {
- name: 'borderColor',
- label: {
- name: SHEET_UI_PLUGIN_NAME + LineColor.name,
- props: {
- color: '#000',
- label: 'borderLine.borderColor',
- getComponent: (ref: LineColor) => (this._lineColor = ref),
- },
- },
- unSelectable: true,
- className: styles.selectColorPickerParent,
- children: [
- {
- label: {
- name: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
- props: {
- onClick: (color: string, e: MouseEvent) => {
- this._lineColor.setColor(color);
- this._borderInfo.color = color;
- const borderItem = this._toolList.find((item) => item.name === 'border');
- const lineColor = borderItem?.children?.find((item) => item.name === 'borderColor');
- if (!lineColor || !lineColor.label) return;
- if (!(lineColor.label as ICustomComponent).props?.color) return;
- (lineColor.label as ICustomComponent).props!.color = color;
- },
- },
- },
- className: styles.selectColorPicker,
- onClick: (...arg) => {
- arg[0].stopPropagation();
- },
- },
- ],
- },
- {
- label: {
- name: SHEET_UI_PLUGIN_NAME + LineBold.name,
- props: {
- img: 0,
- label: 'borderLine.borderSize',
- getComponent: (ref: LineBold) => (this._lineBold = ref),
- },
- },
- onClick: (...arg) => {
- arg[0].stopPropagation();
- const label = BORDER_SIZE_CHILDREN[arg[2]].label;
- if (typeof label === 'string') {
- this._lineBold.setImg(label);
- } else {
- this._lineBold.setImg(label.name);
- }
- this._borderInfo.style = arg[1];
- },
- className: styles.selectLineBoldParent,
- unSelectable: true,
- children: BORDER_SIZE_CHILDREN,
- },
- ],
- },
- {
- type: 5,
- tooltip: 'toolbar.mergeCell.main',
- label: {
- name: 'MergeIcon',
- },
- show: this._config.mergeCell,
- onClick: (value: string) => {
- this.setMerge(value ?? 'all');
- this.hideTooltip();
- },
- name: 'mergeCell',
- children: MERGE_CHILDREN,
- },
- {
- type: 3,
- tooltip: 'toolbar.horizontalAlignMode.main',
- className: styles.selectDoubleString,
- display: 1,
- name: 'horizontalAlignMode',
- show: this._config.horizontalAlignMode,
- onClick: (value: HorizontalAlign) => {
- this.setHorizontalAlignment(value);
- this.hideTooltip();
- },
- children: HORIZONTAL_ALIGN_CHILDREN,
- },
- {
- type: 3,
- tooltip: 'toolbar.verticalAlignMode.main',
- className: styles.selectDoubleString,
- display: 1,
- name: 'verticalAlignMode',
- show: this._config.verticalAlignMode,
- onClick: (value: VerticalAlign) => {
- this.setVerticalAlignment(value);
- this.hideTooltip();
- },
- children: VERTICAL_ALIGN_CHILDREN,
- },
- {
- type: 3,
- className: styles.selectDoubleString,
- tooltip: 'toolbar.textWrapMode.main',
- display: 1,
- name: 'textWrapMode',
- show: this._config.textWrapMode,
- onClick: (value: WrapStrategy) => {
- this.setWrapStrategy(value);
- this.hideTooltip();
- },
- children: TEXT_WRAP_CHILDREN,
- },
- {
- type: 3,
- className: styles.selectDoubleString,
- name: 'textRotateMode',
- tooltip: 'toolbar.textRotateMode.main',
- display: 1,
- show: this._config.textRotateMode,
- onClick: (value: number | string) => {
- this.setTextRotation(value);
- this.hideTooltip();
- },
- children: TEXT_ROTATE_CHILDREN,
- },
- ];
+ // this._config = Tools.deepMerge({}, DefaultToolbarConfig, config);
this._initialize();
}
@@ -409,202 +109,42 @@ export class ToolbarUIController extends Disposable {
this._globalObserverManager.requiredObserver<UIObserver<T>>('onUIChangeObservable', 'core').notifyObservers(msg);
}
- changeColor(color: string) {
- this.setFontColor(color);
- }
-
- setFontFamily(fontFamily: string) {
- const msg = {
- name: 'fontFamily',
- value: fontFamily,
- };
- this.setUIObserve(msg);
- }
-
- setFontSize(fontSize: number) {
- const msg = {
- name: 'fontSize',
- value: fontSize,
- };
- this.setUIObserve<number>(msg);
- }
-
- setFontColor(color: string) {
- const msg = {
- name: 'fontColor',
- value: color,
- };
- this.setUIObserve(msg);
- }
-
- setBackground(color: string) {
- const msg = {
- name: 'background',
- value: color,
- };
- this.setUIObserve(msg);
- }
-
- setMerge(value: string) {
- const msg = {
- name: 'merge',
- value,
- };
- this.setUIObserve(msg);
- }
-
- setTextRotation(value: string | number) {
- const msg = {
- name: 'textRotation',
- value,
- };
- this.setUIObserve(msg);
- }
-
- setWrapStrategy(value: WrapStrategy) {
- const msg = {
- name: 'wrapStrategy',
- value,
- };
- this.setUIObserve<number>(msg);
- }
-
- setVerticalAlignment(value: VerticalAlign) {
- const msg = {
- name: 'verticalAlignment',
- value,
- };
- this.setUIObserve<number>(msg);
- }
-
- setHorizontalAlignment(value: HorizontalAlign) {
- const msg = {
- name: 'horizontalAlignment',
- value,
- };
- this.setUIObserve<number>(msg);
- }
-
- setBorder() {
- const msg = {
- name: 'borderInfo',
- value: this._borderInfo,
- };
- this.setUIObserve<IKeyValue>(msg);
- }
-
- hideTooltip() {
- const dom = this._toolbar.base as HTMLDivElement;
- const tooltip = dom.querySelectorAll(`.${styles.tooltipTitle}.${styles.bottom}`);
- tooltip.forEach((item) => {
- (item as HTMLSpanElement).style.display = 'none';
- });
- }
-
- // eslint-disable-next-line max-lines-per-function
- private _changeToolbarState(range: Range): void {
- // FIXME@wzhudev: this is anti-pattern too, it should not compose all the toolbar items here
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
- const worksheet = workbook.getActiveSheet();
- if (worksheet) {
- const fontSize = range.getFontSize();
- const fontWeight = range.getFontWeight();
- const fontName = range.getFontFamily();
- const fontItalic = range.getFontStyle();
- const horizontalAlign = range.getHorizontalAlignment() ?? HorizontalAlign.LEFT;
- const verticalAlign = range.getVerticalAlignment() ?? VerticalAlign.BOTTOM;
- const rotation = range.getTextRotation() as ITextRotation;
- const warp = range.getWrapStrategy() ?? WrapStrategy.CLIP;
-
- const textRotateModeItem = this._toolList.find((item) => item.name === 'textRotateMode');
- const fontSizeItem = this._toolList.find((item) => item.name === 'fontSize');
- const fontNameItem = this._toolList.find((item) => item.name === 'font');
- const fontBoldItem = this._toolList.find((item) => item.name === 'bold');
- const fontItalicItem = this._toolList.find((item) => item.name === 'italic');
- const horizontalAlignModeItem = this._toolList.find((item) => item.name === 'horizontalAlignMode');
- const verticalAlignModeItem = this._toolList.find((item) => item.name === 'verticalAlignMode');
- const textWrapMode = this._toolList.find((item) => item.name === 'textWrapMode');
-
- if (fontNameItem) {
- fontNameItem.children?.forEach((item) => {
- item.selected = fontName === item.value;
- });
- }
- if (fontSizeItem) {
- fontSizeItem.label = fontSize.toString();
- }
- if (fontBoldItem) {
- fontBoldItem.active = !!fontWeight;
- }
- if (fontItalicItem) {
- fontItalicItem.active = !!fontItalic;
- }
- if (horizontalAlignModeItem) {
- horizontalAlignModeItem.children?.forEach((item) => {
- item.selected = horizontalAlign === item.value;
- });
- }
- if (textRotateModeItem) {
- textRotateModeItem.children?.forEach((item) => {
- if ((rotation as ITextRotation).v) {
- item.selected = item.value === 'v';
- } else {
- item.selected = (rotation as ITextRotation).a === item.value;
- }
- });
- }
- if (verticalAlignModeItem) {
- verticalAlignModeItem.children?.forEach((item) => {
- item.selected = verticalAlign === item.value;
- });
- }
- if (textWrapMode) {
- textWrapMode.children?.forEach((item) => {
- item.selected = warp === item.value;
- });
- }
-
- this.setToolbar();
- }
- }
-
- private _initializeToolbar(): void {
- // NOTE@wzhudev: now we register menu items that only display in the toolbar here. In fact we should register all commands and menu items and shortcuts
- // in a single controller. I will do that layer.
- [UndoMenuItemFactory, RedoMenuItemFactory, BoldMenuItemFactory, ItalicMenuItemFactory, UnderlineMenuItemFactory, StrikeThroughMenuItemFactory].forEach((factory) => {
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
- });
- }
-
private _initialize() {
+ // TODO@wzhudev: this should be builtin and requires no registration process.
const componentManager = this._componentManager;
componentManager.register(SHEET_UI_PLUGIN_NAME + ColorSelect.name, ColorSelect);
componentManager.register(SHEET_UI_PLUGIN_NAME + ColorPicker.name, ColorPicker);
componentManager.register(SHEET_UI_PLUGIN_NAME + LineColor.name, LineColor);
componentManager.register(SHEET_UI_PLUGIN_NAME + LineBold.name, LineBold);
+ }
- CommandManager.getCommandObservers().add(({ actions }) => {
- if (!actions || actions.length === 0) return;
- const action = actions[0] as SheetActionBase<ISheetActionData, ISheetActionData, void>;
-
- const currentUnitId = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getUnitId();
-
- // TODO not use try catch
- try {
- action.getWorkBook();
- } catch (error) {
- return;
- }
-
- const actionUnitId = action.getWorkBook().getUnitId();
-
- if (currentUnitId !== actionUnitId) return;
-
- const manager = this._selectionManager;
- const range = manager.getCurrentCell();
- if (range) {
- this._changeToolbarState(range);
- }
+ private _initializeToolbar(): void {
+ // TODO: @wzhudev: now we register menu items that only display in the toolbar here. In fact we should register all commands and menu items and shortcuts
+ // in a single controller. I will do that layer.
+ (
+ [
+ UndoMenuItemFactory,
+ RedoMenuItemFactory,
+ BoldMenuItemFactory,
+ ItalicMenuItemFactory,
+ UnderlineMenuItemFactory,
+ StrikeThroughMenuItemFactory,
+ FontFamilySelectorMenuItemFactory,
+ FontSizeSelectorMenuItemFactory,
+ ResetTextColorMenuItemFactory,
+ TextColorSelectorMenuItemFactory,
+ BackgroundColorSelectorMenuItemFactory,
+ ResetBackgroundColorMenuItemFactory,
+ CellBorderSelectorMenuItemFactory,
+ SetBorderColorMenuItemFactory,
+ SetBorderStyleMenuItemFactory,
+ HorizontalAlignMenuItemFactory,
+ VerticalAlignMenuItemFactory,
+ WrapTextMenuItemFactory,
+ TextRotateMenuItemFactory,
+ ] as IMenuItemFactory[]
+ ).forEach((factory) => {
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
});
}
}
diff --git a/packages/ui-plugin-sheets/src/Controller/menu.ts b/packages/ui-plugin-sheets/src/Controller/menu.ts
index c6f4f70c92..abaacbb074 100644
--- a/packages/ui-plugin-sheets/src/Controller/menu.ts
+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts
@@ -9,53 +9,90 @@ import {
SetStrikeThroughCommand,
SetUnderlineCommand,
SetRangeStyleMutation,
- DeleteRangeCommand,
SetWorksheetColWidthCommand,
SetWorksheetRowHeightCommand,
RemoveRowCommand,
RemoveColCommand,
+ SetFontFamilyCommand,
+ SetFontSizeCommand,
+ SetTextColorCommand,
+ SetBackgroundColorCommand,
+ SetTextRotationCommand,
+ SetTextWrapCommand,
+ SetHorizontalTextAlignCommand,
+ SetVerticalTextAlignCommand,
+ ResetTextColorCommand,
+ ResetBackgroundColorCommand,
+ DeleteRangeMoveLeftCommand,
+ DeleteRangeMoveUpCommand,
+ RemoveSheetCommand,
+ SetWorksheetRowHideCommand,
+ SetWorksheetRowShowCommand,
+ SetWorksheetHideCommand,
} from '@univerjs/base-sheets';
-import { IMenuItem, MenuPosition } from '@univerjs/base-ui';
-import { FontItalic, FontWeight, ICommandService, IPermissionService, IUndoRedoService, RedoCommand, UndoCommand } from '@univerjs/core';
+import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes } from '@univerjs/base-ui';
+import {
+ FontItalic,
+ FontWeight,
+ HorizontalAlign,
+ ICommandService,
+ IPermissionService,
+ IUndoRedoService,
+ RedoCommand,
+ UndoCommand,
+ VerticalAlign,
+ WrapStrategy,
+} from '@univerjs/core';
+
import { IAccessor } from '@wendellhu/redi';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
+import { ISetHorizontalTextAlignCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams } from '@univerjs/base-sheets/src/Commands/Commands/set-style.command';
import { RightMenuInput } from '../View';
+import { FONT_FAMILY_CHILDREN, FONT_SIZE_CHILDREN, HORIZONTAL_ALIGN_CHILDREN, TEXT_ROTATE_CHILDREN, TEXT_WRAP_CHILDREN, VERTICAL_ALIGN_CHILDREN } from '../View/Toolbar/Const';
+import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const/PLUGIN_NAME';
-export function UndoMenuItemFactory(accessor: IAccessor): IMenuItem {
+export { SetBorderColorMenuItemFactory, SetBorderStyleMenuItemFactory } from './menu/border.menu';
+
+export function UndoMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
const undoRedoService = accessor.get(IUndoRedoService);
return {
id: UndoCommand.id,
+ type: MenuItemType.BUTTON,
icon: 'ForwardIcon',
title: 'Undo',
- menu: [MenuPosition.TOOLBAR],
+ positions: [MenuPosition.TOOLBAR],
disabled$: undoRedoService.undoRedoStatus$.pipe(map((v) => v.undos <= 0)),
};
}
-export function RedoMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function RedoMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
const undoRedoService = accessor.get(IUndoRedoService);
return {
id: RedoCommand.id,
+ type: MenuItemType.BUTTON,
icon: 'BackIcon',
title: 'Redo',
- menu: [MenuPosition.TOOLBAR],
+ positions: [MenuPosition.TOOLBAR],
disabled$: undoRedoService.undoRedoStatus$.pipe(map((v) => v.redos <= 0)),
};
}
-export function BoldMenuItemFactory(accessor: IAccessor): IMenuItem {
+// TODO@wzhudev: in the future we will support add rich format value to in-cell texts. Then we would make some changes to how these menu items works.
+
+export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
const commandService = accessor.get(ICommandService);
const permissionService = accessor.get(IPermissionService);
const selectionManager = accessor.get(ISelectionManager);
return {
id: SetBoldCommand.id,
+ type: MenuItemType.BUTTON,
icon: 'BoldIcon',
title: 'Set bold',
- menu: [MenuPosition.TOOLBAR],
+ positions: [MenuPosition.TOOLBAR],
disabled$: new Observable<boolean>((subscriber) => {
let editable = false;
function update() {
@@ -75,33 +112,35 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuItem {
};
}),
activated$: new Observable<boolean>((subscriber) => {
- commandService.onCommandExecuted((c) => {
+ const disposable = commandService.onCommandExecuted((c) => {
const id = c.id;
if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
return;
}
- // FIXME: range is undefined when moving selection with cursor
const range = selectionManager.getCurrentCell();
const isBold = range?.getFontWeight();
subscriber.next(isBold === FontWeight.BOLD);
});
+
subscriber.next(false);
+ return disposable.dispose;
}),
};
}
-export function ItalicMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
const permissionService = accessor.get(IPermissionService);
const commandService = accessor.get(ICommandService);
const selectionManager = accessor.get(ISelectionManager);
return {
id: SetItalicCommand.id,
+ type: MenuItemType.BUTTON,
icon: 'ItalicIcon',
title: 'Set italic',
- menu: [MenuPosition.TOOLBAR],
+ positions: [MenuPosition.TOOLBAR],
disabled$: new Observable<boolean>((subscriber) => {
let editable = false;
function update() {
@@ -120,7 +159,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuItem {
};
}),
activated$: new Observable<boolean>((subscriber) => {
- commandService.onCommandExecuted((c) => {
+ const disposable = commandService.onCommandExecuted((c) => {
const id = c.id;
if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
return;
@@ -131,21 +170,24 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuItem {
subscriber.next(isItalic === FontItalic.ITALIC);
});
+
subscriber.next(false);
+ return disposable.dispose;
}),
};
}
-export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
const permissionService = accessor.get(IPermissionService);
const commandService = accessor.get(ICommandService);
const selectionManager = accessor.get(ISelectionManager);
return {
id: SetUnderlineCommand.id,
+ type: MenuItemType.BUTTON,
icon: 'UnderLineIcon',
title: 'Set underline',
- menu: [MenuPosition.TOOLBAR],
+ positions: [MenuPosition.TOOLBAR],
disabled$: new Observable<boolean>((subscriber) => {
let editable = false;
function update() {
@@ -164,7 +206,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuItem {
};
}),
activated$: new Observable<boolean>((subscriber) => {
- commandService.onCommandExecuted((c) => {
+ const disposable = commandService.onCommandExecuted((c) => {
const id = c.id;
if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
return;
@@ -175,21 +217,24 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuItem {
subscriber.next(!!(isUnderline && isUnderline.s));
});
+
subscriber.next(false);
+ return disposable.dispose;
}),
};
}
-export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
const permissionService = accessor.get(IPermissionService);
const commandService = accessor.get(ICommandService);
const selectionManager = accessor.get(ISelectionManager);
return {
id: SetStrikeThroughCommand.id,
+ type: MenuItemType.BUTTON,
icon: 'DeleteLineIcon',
title: 'Set strike through',
- menu: [MenuPosition.TOOLBAR],
+ positions: [MenuPosition.TOOLBAR],
disabled$: new Observable<boolean>((subscriber) => {
let editable = false;
function update() {
@@ -208,7 +253,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuItem {
};
}),
activated$: new Observable<boolean>((subscriber) => {
- commandService.onCommandExecuted((c) => {
+ const disposable = commandService.onCommandExecuted((c) => {
const id = c.id;
if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
return;
@@ -219,83 +264,384 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuItem {
subscriber.next(!!(st && st.s));
});
+
subscriber.next(false);
+ return disposable.dispose;
+ }),
+ };
+}
+
+export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ const permissionService = accessor.get(IPermissionService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+
+ return {
+ id: SetFontFamilyCommand.id,
+ title: 'toolbar.font',
+ tooltip: 'toolbar.font',
+ selectType: SelectTypes.NEO,
+ type: MenuItemType.SELECTOR,
+ display: DisplayTypes.FONT,
+ positions: [MenuPosition.TOOLBAR],
+ selections: FONT_FAMILY_CHILDREN,
+ disabled$: new Observable((subscriber) => {
+ let editable = false;
+ function update() {
+ subscriber.next(!editable);
+ }
+
+ update();
+
+ const permission$ = permissionService.editable$.subscribe((e) => {
+ editable = e;
+ update();
+ });
+
+ return () => {
+ permission$.unsubscribe();
+ };
+ }),
+ value$: new Observable((subscriber) => {
+ const defaultValue = FONT_FAMILY_CHILDREN[0].value;
+
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+ if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
+ return;
+ }
+
+ const range = selectionManager.getCurrentCell();
+ const ff = range?.getFontFamily();
+
+ subscriber.next(ff ?? defaultValue);
+ });
+
+ subscriber.next(defaultValue);
+ return disposable.dispose;
}),
};
}
-export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuItem {}
+export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {
+ const permissionService = accessor.get(IPermissionService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+
+ return {
+ id: SetFontSizeCommand.id,
+ title: 'fontSize',
+ tooltip: 'toolbar.fontSize',
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.NEO,
+ display: DisplayTypes.INPUT,
+ positions: [MenuPosition.TOOLBAR],
+ selections: FONT_SIZE_CHILDREN,
+ disabled$: new Observable<boolean>((subscriber) => {
+ let editable = false;
+ function update() {
+ subscriber.next(!editable);
+ }
+
+ update();
-export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuItem {}
+ const permission$ = permissionService.editable$.subscribe((e) => {
+ editable = e;
+ update();
+ });
-export function FontColorSelectorMenuItemFactory(accessor: IAccessor): IMenuItem {}
+ return () => {
+ permission$.unsubscribe();
+ };
+ }),
+ value$: new Observable((subscriber) => {
+ const DEFAULT_SIZE = 14;
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+ if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
+ return;
+ }
+
+ const range = selectionManager.getCurrentCell();
+ const fs = range?.getFontSize() ?? DEFAULT_SIZE;
+
+ subscriber.next(fs);
+ });
+
+ subscriber.next(DEFAULT_SIZE);
+
+ return disposable.dispose;
+ }),
+ };
+}
-export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuItem {}
+export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: ResetTextColorCommand.id,
+ type: MenuItemType.BUTTON,
+ title: 'toolbar.resetColor',
+ positions: SetTextColorCommand.id,
+ };
+}
-export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuItem {}
+export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
-export function MergeCellMenuItemFactory(accessor: IAccessor): IMenuItem {}
+ return {
+ id: SetTextColorCommand.id,
+ title: 'toolbar.textColor.main',
+ icon: 'TextColorIcon',
+ tooltip: 'toolbar.textColor.main',
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.NEO,
+ positions: [MenuPosition.TOOLBAR],
+ display: DisplayTypes.COLOR,
+ selections: [
+ {
+ id: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
+ },
+ ],
+ value$: new Observable<string>((subscriber) => {
+ const defaultColor = '#000';
+ const disposable = commandService.onCommandExecuted((c) => {
+ if (c.id === SetTextColorCommand.id) {
+ const color = (c.params as { value: string }).value;
+ subscriber.next(color ?? defaultColor);
+ }
+ });
-export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuItem {}
+ subscriber.next(defaultColor);
+ return disposable.dispose;
+ }),
+ };
+}
-export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuItem {}
+export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: ResetBackgroundColorCommand.id,
+ type: MenuItemType.BUTTON,
+ title: 'toolbar.resetColor',
+ positions: SetBackgroundColorCommand.id,
+ };
+}
-export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuItem {}
+export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
-export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuItem {}
+ return {
+ id: SetBackgroundColorCommand.id,
+ tooltip: 'toolbar.fillColor.main',
+ title: 'TextColorIcon',
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.NEO,
+ positions: [MenuPosition.TOOLBAR],
+ display: DisplayTypes.COLOR,
+ icon: 'FillColorIcon',
+ selections: [
+ {
+ id: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
+ },
+ ],
+ value$: new Observable<string>((subscriber) => {
+ const defaultColor = '#fff';
+ const disposable = commandService.onCommandExecuted((c) => {
+ if (c.id === SetBackgroundColorCommand.id) {
+ const color = (c.params as { value: string }).value;
+ subscriber.next(color ?? defaultColor);
+ }
+ });
-export function NumberFormatMenuItemFactory(accessor: IAccessor): IMenuItem {}
+ subscriber.next(defaultColor);
+ return disposable.dispose;
+ }),
+ };
+}
-// NOTE: these menu icons should be registered by plugins not defined here.
-// export function SearchReplaceMenuItemFactory(accessor: IAccessor): IMenuItem {}
-// export function ImportMenuItemFactory(accessor: IAccessor): IMenuItem {}
-// export function ImageMenuItemFactory(accessor: IAccessor): IMenuItem {}
+// Merge cell command is not ready yet.
+// export function MergeCellMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+// return {
+// }
+// }
-export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<HorizontalAlign> {
+ return {
+ id: SetHorizontalTextAlignCommand.id,
+ title: 'horizontalAlignMode',
+ icon: HORIZONTAL_ALIGN_CHILDREN[0].icon,
+ positions: [MenuPosition.TOOLBAR],
+ tooltip: 'toolbar.horizontalAlignMode.main',
+ display: DisplayTypes.ICON,
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.NEO,
+ selections: HORIZONTAL_ALIGN_CHILDREN,
+ value$: new Observable<HorizontalAlign>((subscriber) => {
+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {
+ if (c.id === SetHorizontalTextAlignCommand.id) {
+ const align = (c.params as ISetHorizontalTextAlignCommandParams).value;
+ subscriber.next(align);
+ }
+ });
+
+ subscriber.next(HorizontalAlign.LEFT);
+
+ return disposable.dispose;
+ }),
+ };
+}
+
+export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<VerticalAlign> {
+ return {
+ id: SetVerticalTextAlignCommand.id,
+ title: 'verticalAlignMode',
+ icon: VERTICAL_ALIGN_CHILDREN[0].icon,
+ tooltip: 'toolbar.verticalAlignMode.main',
+ display: DisplayTypes.ICON,
+ type: MenuItemType.SELECTOR,
+ positions: [MenuPosition.TOOLBAR],
+ selectType: SelectTypes.NEO,
+ selections: VERTICAL_ALIGN_CHILDREN,
+ value$: new Observable<VerticalAlign>((subscriber) => {
+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {
+ if (c.id === SetVerticalTextAlignCommand.id) {
+ const align = (c.params as ISetVerticalTextAlignCommandParams).value;
+ subscriber.next(align);
+ }
+ });
+
+ subscriber.next(VerticalAlign.TOP);
+
+ return disposable.dispose;
+ }),
+ };
+}
+
+export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<WrapStrategy> {
+ return {
+ id: SetTextWrapCommand.id,
+ title: 'textWrapMode',
+ tooltip: 'toolbar.textWrapMode.main',
+ icon: TEXT_WRAP_CHILDREN[0].icon,
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.NEO,
+ positions: [MenuPosition.TOOLBAR],
+ selections: TEXT_WRAP_CHILDREN,
+ display: DisplayTypes.ICON,
+ value$: new Observable((subscriber) => {
+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {
+ if (c.id === SetTextWrapCommand.id) {
+ const wrap = (c.params as ISetTextWrapCommandParams).value;
+ subscriber.next(wrap ?? WrapStrategy.OVERFLOW);
+ }
+ });
+
+ subscriber.next(WrapStrategy.OVERFLOW);
+
+ return disposable.dispose;
+ }),
+ };
+}
+
+export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number | string> {
+ return {
+ id: SetTextRotationCommand.id,
+ title: 'textRotateMode',
+ tooltip: 'toolbar.textRotateMode.main',
+ icon: TEXT_ROTATE_CHILDREN[0].icon,
+ display: DisplayTypes.ICON,
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.NEO,
+ selections: TEXT_ROTATE_CHILDREN,
+ positions: [MenuPosition.TOOLBAR],
+ value$: new Observable<number | string>((subscriber) => {
+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {
+ if (c.id === SetTextRotationCommand.id) {
+ const rotation = (c.params as { value: number | string }).value;
+ subscriber.next(rotation ?? 0);
+ }
+ });
+
+ subscriber.next(0);
+
+ return disposable.dispose;
+ }),
+ };
+}
+
+export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: ClearSelectionContentCommand.id,
+ type: MenuItemType.BUTTON,
title: 'rightClick.clearContent',
- menu: [MenuPosition.CONTEXT_MENU],
+ positions: [MenuPosition.CONTEXT_MENU],
};
}
-export function InsertRowMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function InsertRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: InsertRowCommand.id,
- menu: [MenuPosition.CONTEXT_MENU],
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.insertRow',
};
}
-export function InsertColMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function InsertColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: InsertColCommand.id,
- menu: [MenuPosition.CONTEXT_MENU],
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.insertColumn',
};
}
-export function RemoveRowMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function RemoveRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: RemoveRowCommand.id,
- menu: [MenuPosition.CONTEXT_MENU],
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.deleteSelectedRow',
};
}
-export function RemoveColMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function HideRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: SetWorksheetRowHideCommand.id,
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.CONTEXT_MENU],
+ title: 'rightClick.hideSelectedRow',
+ };
+}
+
+export function ShowRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: SetWorksheetRowShowCommand.id,
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.CONTEXT_MENU],
+ title: 'rightClick.showHideRow',
+ };
+}
+
+export function RemoveColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: RemoveColCommand.id,
- menu: [MenuPosition.CONTEXT_MENU],
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.deleteSelectedColumn',
};
}
-export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+
return {
id: SetWorksheetRowHeightCommand.id,
- menu: [MenuPosition.CONTEXT_MENU],
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.rowHeight',
+ display: DisplayTypes.CUSTOM,
label: {
name: RightMenuInput.name,
props: {
@@ -303,13 +649,36 @@ export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuItem {
suffix: 'px',
},
},
+ value$: new Observable((subscriber) => {
+ function update() {
+ const range = selectionManager.getCurrentCell();
+ const rowHeight = range?.getHeight();
+
+ subscriber.next(rowHeight ?? 0);
+ }
+
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+ if (id === SetRangeStyleMutation.id || id === SetSelectionsOperation.id) {
+ return update();
+ }
+ });
+
+ update();
+ return disposable.dispose;
+ }),
};
}
-export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+
return {
id: SetWorksheetColWidthCommand.id,
- menu: [MenuPosition.CONTEXT_MENU],
+ type: MenuItemType.BUTTON,
+ display: DisplayTypes.CUSTOM,
+ positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.columnWidth',
label: {
name: RightMenuInput.name,
@@ -318,31 +687,124 @@ export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuItem {
suffix: 'px',
},
},
+ value$: new Observable((subscriber) => {
+ function update() {
+ const range = selectionManager.getCurrentCell();
+ const rowHeight = range?.getWidth();
+
+ subscriber.next(rowHeight ?? 0);
+ }
+
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+ if (id === SetRangeStyleMutation.id || id === SetSelectionsOperation.id) {
+ return update();
+ }
+ });
+
+ update();
+ return disposable.dispose;
+ }),
};
}
-export function DeleteRangeMenuItemFactory(accessor: IAccessor): IMenuItem {
+const DELETE_RANGE_MENU_ID = 'sheet.menu.delete-range';
+export function DeleteRangeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
return {
- id: `${DeleteRangeCommand.id}.parent`,
- menu: [MenuPosition.CONTEXT_MENU],
+ id: DELETE_RANGE_MENU_ID,
+ type: MenuItemType.SUBITEMS,
title: 'rightClick.deleteCell',
- subMenus: [DeleteRangeCommand.id, `${DeleteRangeCommand.id}up`],
+ positions: [MenuPosition.CONTEXT_MENU],
+ selectType: SelectTypes.NEO,
};
}
-export function DeleteRangeMoveLeftMenuItemFactory(accessor: IAccessor): IMenuItem {
+
+export function DeleteRangeMoveLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
- id: DeleteRangeCommand.id,
- menu: [MenuPosition.CONTEXT_MENU],
+ id: DeleteRangeMoveLeftCommand.id,
+ type: MenuItemType.BUTTON,
title: 'rightClick.moveLeft',
- parentId: `${DeleteRangeCommand.id}.parent`,
+ positions: DELETE_RANGE_MENU_ID,
};
}
-export function DeleteRangeMoveUpMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function DeleteRangeMoveUpMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
- id: `${DeleteRangeCommand.id}up`,
- menu: [MenuPosition.CONTEXT_MENU],
+ id: DeleteRangeMoveUpCommand.id,
+ type: MenuItemType.BUTTON,
title: 'rightClick.moveUp',
- parentId: `${DeleteRangeCommand.id}.parent`,
+ positions: DELETE_RANGE_MENU_ID,
+ };
+}
+
+// right menu in main sheet bar
+export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: RemoveSheetCommand.id,
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.delete',
+ };
+}
+
+export function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ // TODO@Dushusir use real command id
+ id: 'CopySheetCommand.id',
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.copy',
+ };
+}
+
+// TODO@Dushusir onClick to rename tab
+// No need to trigger command after clicking,maybe no need Command id?
+export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: 'RenameSheetCommand.id',
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.rename',
+ onClick: () => {
+ // TODO@Dushusir 这里能监听到点击事件,但是无法触发到 this._sheetBar.reNameSheet(this._dataId);
+ // 或许不应该通过这里的onClick直接更新UI?
+ console.info('rename=========');
+ },
+ };
+}
+
+// TODO@Dushusir add command
+export function ChangeColorSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ return {
+ id: 'ChangeColorSheetCommand.id',
+ title: 'sheetConfig.changeColor',
+ positions: [MenuPosition.SHEET_BAR],
+ display: DisplayTypes.COLOR,
+ selectType: SelectTypes.NEO,
+ type: MenuItemType.SELECTOR,
+ selections: [
+ {
+ id: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
+ },
+ ],
+ };
+}
+
+export function HideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: SetWorksheetHideCommand.id,
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.hide',
+ };
+}
+
+// TODO@Dushusir use show worksheet command
+export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: 'SetWorksheetHideCommand.id',
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.unhide',
};
}
diff --git a/packages/ui-plugin-sheets/src/Controller/menu/border.menu.ts b/packages/ui-plugin-sheets/src/Controller/menu/border.menu.ts
new file mode 100644
index 0000000000..cbe43daac9
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/Controller/menu/border.menu.ts
@@ -0,0 +1,169 @@
+import { BorderStyleManagerService, ISelectionManager, SetBorderColorCommand, SetBorderPositionCommand, SetBorderStyleCommand } from '@univerjs/base-sheets';
+import { ColorPicker, DisplayTypes, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes } from '@univerjs/base-ui';
+import { BorderStyleTypes, ICommandService, IPermissionService } from '@univerjs/core';
+import { IAccessor } from '@wendellhu/redi';
+import { map } from 'rxjs/operators';
+
+import { SHEET_UI_PLUGIN_NAME } from '../../Basics/Const/PLUGIN_NAME';
+import { LineBold } from '../../View';
+
+export const BORDER_LINE_CHILDREN = [
+ {
+ label: 'borderLine.borderTop',
+ icon: 'TopBorderIcon',
+ value: 'top',
+ },
+ {
+ label: 'borderLine.borderBottom',
+ icon: 'BottomBorderIcon',
+ value: 'bottom',
+ },
+ {
+ label: 'borderLine.borderLeft',
+ icon: 'LeftBorderIcon',
+ value: 'left',
+ },
+ {
+ label: 'borderLine.borderRight',
+ icon: 'RightBorderIcon',
+ value: 'right',
+ },
+ {
+ label: 'borderLine.borderNone',
+ icon: 'NoneBorderIcon',
+ value: 'none',
+ },
+ {
+ label: 'borderLine.borderAll',
+ icon: 'FullBorderIcon',
+ value: 'all',
+ },
+ {
+ label: 'borderLine.borderOutside',
+ icon: 'OuterBorderIcon',
+ value: 'outside',
+ },
+ {
+ label: 'borderLine.borderInside',
+ icon: 'InnerBorderIcon',
+ value: 'inside',
+ },
+ {
+ label: 'borderLine.borderHorizontal',
+ icon: 'StripingBorderIcon',
+ value: 'horizontal',
+ },
+ {
+ label: 'borderLine.borderVertical',
+ icon: 'VerticalBorderIcon',
+ value: 'vertical',
+ },
+];
+
+export const BORDER_SIZE_CHILDREN = [
+ {
+ label: 'borderLine.borderNone',
+ value: BorderStyleTypes.NONE,
+ },
+ {
+ label: 'BorderThin',
+ value: BorderStyleTypes.THIN,
+ },
+ {
+ label: 'BorderHair',
+ value: BorderStyleTypes.HAIR,
+ },
+ {
+ label: 'BorderDotted',
+ value: BorderStyleTypes.DOTTED,
+ },
+ {
+ label: 'BorderDashed',
+ value: BorderStyleTypes.DASHED,
+ },
+ {
+ label: 'BorderDashDot',
+ value: BorderStyleTypes.DOTTED,
+ },
+ {
+ label: 'BorderDashDotDot',
+ value: BorderStyleTypes.DASH_DOT_DOT,
+ },
+ {
+ label: 'BorderMedium',
+ value: BorderStyleTypes.MEDIUM,
+ },
+ {
+ label: 'BorderMediumDashed',
+ value: BorderStyleTypes.MEDIUM_DASHED,
+ },
+ {
+ label: 'BorderMediumDashDot',
+ value: BorderStyleTypes.MEDIUM_DASH_DOT,
+ },
+ {
+ label: 'BorderMediumDashDotDot',
+ value: BorderStyleTypes.MEDIUM_DASH_DOT_DOT,
+ },
+ {
+ label: 'BorderThick',
+ value: BorderStyleTypes.THICK,
+ },
+];
+
+export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ const permissionService = accessor.get(IPermissionService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+ const borderStyleManagerService = accessor.get(BorderStyleManagerService);
+ return {
+ id: SetBorderPositionCommand.id,
+ title: 'border',
+ icon: 'FullBorderIcon',
+ display: DisplayTypes.ICON,
+ positions: [MenuPosition.TOOLBAR],
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.NEO,
+ selections: [...BORDER_LINE_CHILDREN],
+ value$: borderStyleManagerService.borderInfo$.pipe(map((info) => info.color)),
+ };
+}
+
+export function SetBorderColorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ const permissionService = accessor.get(IPermissionService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+ const borderStyleManagerService = accessor.get(BorderStyleManagerService);
+ return {
+ id: SetBorderColorCommand.id,
+ title: 'border',
+ positions: SetBorderPositionCommand.id,
+ display: DisplayTypes.COLOR,
+ selectType: SelectTypes.NEO,
+ type: MenuItemType.SELECTOR,
+ selections: [
+ {
+ id: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
+ },
+ ],
+ value$: borderStyleManagerService.borderInfo$.pipe(map((info) => info.color)),
+ };
+}
+
+export function SetBorderStyleMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<BorderStyleTypes> {
+ const permissionService = accessor.get(IPermissionService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+ const borderStyleManagerService = accessor.get(BorderStyleManagerService);
+ return {
+ id: SetBorderStyleCommand.id,
+ title: 'borderLine.borderSize',
+ label: SHEET_UI_PLUGIN_NAME + LineBold.name,
+ positions: SetBorderPositionCommand.id,
+ display: DisplayTypes.CUSTOM,
+ selectType: SelectTypes.NEO,
+ type: MenuItemType.SELECTOR,
+ selections: [...BORDER_SIZE_CHILDREN],
+ value$: borderStyleManagerService.borderInfo$.pipe(map((info) => info.style)),
+ };
+}
diff --git a/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts b/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts
index 9754d107d3..049d4af331 100644
--- a/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts
+++ b/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts
@@ -1,4 +1,13 @@
-import { ChangeSelectionCommand, ExpandSelectionCommand, SetBoldCommand, SetItalicCommand, SetStrikeThroughCommand, SetUnderlineCommand } from '@univerjs/base-sheets';
+import {
+ ChangeSelectionCommand,
+ ExpandSelectionCommand,
+ SetBoldCommand,
+ SetFontFamilyCommand,
+ SetFontSizeCommand,
+ SetItalicCommand,
+ SetStrikeThroughCommand,
+ SetUnderlineCommand,
+} from '@univerjs/base-sheets';
import { IShortcutService } from '@univerjs/base-ui';
import { Disposable, ICommandService } from '@univerjs/core';
import {
@@ -25,7 +34,17 @@ export class DesktopSheetShortcutController extends Disposable {
constructor(@IShortcutService private readonly _shortcutService: IShortcutService, @ICommandService private readonly _commandService: ICommandService) {
super();
- [ChangeSelectionCommand, ExpandSelectionCommand, SetBoldCommand, SetItalicCommand, SetStrikeThroughCommand, SetUnderlineCommand].forEach((c) => {
+ // NOTE@wzhudev: these commands are just here temporarily
+ [
+ ChangeSelectionCommand,
+ ExpandSelectionCommand,
+ SetBoldCommand,
+ SetItalicCommand,
+ SetStrikeThroughCommand,
+ SetUnderlineCommand,
+ SetFontFamilyCommand,
+ SetFontSizeCommand,
+ ].forEach((c) => {
this.disposeWithMe(this._commandService.registerCommand(c));
});
diff --git a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
index 3f87b4241c..1f2028b2dd 100644
--- a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
@@ -12,6 +12,8 @@ interface IState {
color: string;
}
+// TODO: @wzhudev: why this component is put under ui-plugin-sheet not base-ui?
+/** @deprecated use ColorSelect in base-ui plugin instead */
export class ColorSelect extends Component<IProps, IState> {
override componentDidMount(): void {
this.props.getComponent?.(this);
diff --git a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/index.module.css b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/index.module.css
deleted file mode 100644
index d2777b3979..0000000000
--- a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/index.module.css
+++ /dev/null
@@ -1,11 +0,0 @@
-.color-select {
- position: relative;
-}
-.color-select .color-select-line {
- position: absolute;
- width: 15px;
- height: 5px;
- bottom: 0px;
- left: 50%;
- transform: translate(-50%, 0);
-}
diff --git a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
index df156665dd..c564953e01 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
@@ -1,5 +1,6 @@
import { BaseComponentProps, AppContext, Icon, CustomLabel } from '@univerjs/base-ui';
import { Component } from 'preact';
+import { BORDER_SIZE_CHILDREN } from '../../../Controller/menu/border.menu';
interface IState {
img: string;
@@ -7,10 +8,13 @@ interface IState {
interface IProps extends BaseComponentProps {
label: string;
- img: string;
+ title: string;
+ value: string;
}
export class LineBold extends Component<IProps, IState> {
+ static readonly componentName = 'bold';
+
static override contextType = AppContext;
constructor(props: IProps) {
@@ -30,7 +34,7 @@ export class LineBold extends Component<IProps, IState> {
override componentWillReceiveProps(props: IProps) {
this.setState({
- img: props.img,
+ img: props.value,
});
}
@@ -52,12 +56,19 @@ export class LineBold extends Component<IProps, IState> {
render() {
const { img } = this.state;
- const { label } = this.props;
+ const { title, value } = this.props;
+ const imgComponent = img && this.getImg(img);
+
+ // TODO: display a style according to the value
+ const label = BORDER_SIZE_CHILDREN.find((item) => item.value === value)?.label;
+
return (
<div style={{ paddingBottom: '3px', width: '100%', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span className={'base-sheets-line-bold'} style={{ position: 'relative' }}>
+ <CustomLabel label={title} />
+ <br></br>
<CustomLabel label={label} />
- <div style={{ width: '100%', height: 0, position: 'absolute', left: 0, bottom: '14px' }}>{img.length ? this.getImg(img) : ''}</div>
+ <div style={{ width: '100%', height: 0, position: 'absolute', left: 0, bottom: '14px' }}>{imgComponent}</div>
</span>
<Icon.RightIcon />
</div>
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
index 6f9e9a90ae..ffd07e80e9 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
@@ -1,5 +1,5 @@
import { IMouseEvent } from '@univerjs/base-render';
-import { BaseRightMenuProps, IDisplayMenuItem, IMenuItem, Menu } from '@univerjs/base-ui';
+import { BaseRightMenuProps, IDisplayMenuItem, IMenuItem, Menu, MenuPosition } from '@univerjs/base-ui';
import { Component, createRef } from 'preact';
import { RightMenuProps } from '../../Controller';
import Style from './index.module.less';
@@ -9,7 +9,7 @@ interface IState {
srcElement: any;
eventType: string | null;
children: RightMenuProps[];
- menuItems: IDisplayMenuItem[];
+ menuItems: Array<IDisplayMenuItem<IMenuItem>>;
}
export class RightMenu extends Component<BaseRightMenuProps, IState> {
@@ -40,26 +40,10 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
setMenuListNeo = (menuItems: IMenuItem[]) => {
this.setState({
- menuItems: this.buildMenuTree(menuItems),
+ menuItems,
});
};
- buildMenuTree(items: IMenuItem[], parentId?: string): IDisplayMenuItem[] {
- const tree: IDisplayMenuItem[] = [];
-
- for (const item of items) {
- if (item.parentId === parentId) {
- const treeItem: IDisplayMenuItem = {
- ...item,
- subMenuItems: this.buildMenuTree(items, item.id),
- };
- tree.push(treeItem);
- }
- }
-
- return tree;
- }
-
// TODO:添加到具体的元素
override componentDidMount() {
this.props.getComponent?.(this);
@@ -141,10 +125,6 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
}
render() {
- // if (!this.state.children.length) {
- // return;
- // }
-
const wrapStyles = { ...this.props.style };
const { visible } = this.state;
@@ -158,7 +138,7 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
e.preventDefault();
}}
>
- <Menu ref={this.ulRef} menuItems={this.state.menuItems} menu={this.state.children} onClick={this.handleClick}></Menu>
+ <Menu ref={this.ulRef} menuId={MenuPosition.CONTEXT_MENU} 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 993f34d7a4..c62277fe3f 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
@@ -1,30 +1,32 @@
-import { CustomLabel, Input } from '@univerjs/base-ui';
+import { CustomLabel, ICustomComponentProps, Input } from '@univerjs/base-ui';
import { Component } from 'preact';
-interface IProps {
+interface IProps extends ICustomComponentProps<string> {
prefix: string;
suffix: string;
onKeyUp?: (e: Event) => void;
}
export class RightMenuInput extends Component<IProps> {
- handleClick(e: Event) {
- e.stopPropagation();
- }
-
- handleKeyUp(e: Event) {
- const { onKeyUp } = this.props;
- onKeyUp?.(e);
- }
+ private value = '';
render() {
- const { prefix, suffix } = this.props;
+ const { prefix, suffix, value } = this.props;
return (
- <div>
+ <div onClick={(e) => this.handleClick(e)}>
<CustomLabel label={prefix} />
- <Input onPressEnter={this.handleKeyUp.bind(this)} type="number" placeholder="1" onClick={this.handleClick}></Input>
+ <Input type="number" placeholder="1" value={value} onClick={(e) => e.stopPropagation()} onChange={this.onChange.bind(this)}></Input>
<CustomLabel label={suffix} />
</div>
);
}
+
+ private handleClick(e: Event) {
+ e.stopPropagation();
+ this.props.onChange?.(this.value);
+ }
+
+ private onChange(e: Event) {
+ this.value = (e.target as HTMLInputElement).value;
+ }
}
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index e306e97f3f..25a4e406fe 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -1,4 +1,4 @@
-import { BaseMenuItem, BaseSheetBarProps, Button, CustomLabel, Icon, Menu } from '@univerjs/base-ui';
+import { BaseMenuItem, BaseSheetBarProps, Button, CustomLabel, IDisplayMenuItem, IMenuItem, Icon, Menu } from '@univerjs/base-ui';
import { RefObject, Component, createRef } from 'preact';
import { SheetBarMenu, ISheetBarMenuItem } from './SheetBarMenu';
import styles from './index.module.less';
@@ -8,6 +8,7 @@ type SheetState = {
sheetList: BaseSheetBarProps[];
menuList: BaseSheetBarProps[];
sheetUl: BaseMenuItem[];
+ menuItems: Array<IDisplayMenuItem<IMenuItem>>;
};
export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
@@ -56,6 +57,13 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
this.setState((prevState) => ({ ...value }), fn);
};
+ // TODO@Dushusir remove after refactoring
+ // setSheetUlNeo(menuItems: IMenuItem[]) {
+ // this.setState({
+ // menuItems: buildMenuTree(menuItems),
+ // });
+ // }
+
// 点击按钮左右滑动
scrollLeft = (e: MouseEvent) => {
this.slideTabBar.getScrollbar().scrollX(this.slideTabBar.getScrollbar().getScrollX() - 50);
@@ -206,7 +214,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
</div>
{/* mouse right button context menu */}
- <Menu className={styles.sheetUl} menu={sheetUl} ref={this.ulRef} />
+ <Menu className={styles.sheetUl} menu={sheetUl} menuId={'sheet-bar-right-menu'} ref={this.ulRef} />
{/* prev next scroll button */}
<div className={`${styles.sheetBarOptions} ${styles.sheetBarScrollButton}`}>
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/Const.ts b/packages/ui-plugin-sheets/src/View/Toolbar/Const.ts
index db573b0f9d..1e63ef2f3e 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/Const.ts
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/Const.ts
@@ -1,4 +1,4 @@
-import { BorderStyleTypes } from '@univerjs/core';
+import { HorizontalAlign, VerticalAlign, WrapStrategy } from '@univerjs/core';
export const FONT_SIZE_CHILDREN = [
{
@@ -148,154 +148,6 @@ export const FONT_FAMILY_CHILDREN = [
},
];
-export const BORDER_LINE_CHILDREN = [
- {
- label: 'borderLine.borderTop',
- suffix: {
- name: 'TopBorderIcon',
- },
- value: 'top',
- },
- {
- label: 'borderLine.borderBottom',
- suffix: {
- name: 'BottomBorderIcon',
- },
- value: 'bottom',
- },
- {
- label: 'borderLine.borderLeft',
- suffix: {
- name: 'LeftBorderIcon',
- },
- value: 'left',
- },
- {
- label: 'borderLine.borderRight',
- suffix: {
- name: 'RightBorderIcon',
- },
- value: 'right',
- border: true,
- },
- {
- label: 'borderLine.borderNone',
- suffix: {
- name: 'NoneBorderIcon',
- },
- value: 'none',
- },
- {
- label: 'borderLine.borderAll',
- suffix: {
- name: 'FullBorderIcon',
- },
- value: 'all',
- selected: true,
- },
- {
- label: 'borderLine.borderOutside',
- suffix: {
- name: 'OuterBorderIcon',
- },
- value: 'outside',
- },
- {
- label: 'borderLine.borderInside',
- suffix: {
- name: 'InnerBorderIcon',
- },
- value: 'inside',
- },
- {
- label: 'borderLine.borderHorizontal',
- suffix: {
- name: 'StripingBorderIcon',
- },
- value: 'horizontal',
- },
- {
- label: 'borderLine.borderVertical',
- suffix: {
- name: 'VerticalBorderIcon',
- },
- value: 'vertical',
- },
-];
-
-export const BORDER_SIZE_CHILDREN = [
- {
- label: 'borderLine.borderNone',
- value: BorderStyleTypes.NONE,
- },
- {
- label: {
- name: 'BorderThin',
- },
- value: BorderStyleTypes.THIN,
- },
- {
- label: {
- name: 'BorderHair',
- },
- value: BorderStyleTypes.HAIR,
- },
- {
- label: {
- name: 'BorderDotted',
- },
- value: BorderStyleTypes.DOTTED,
- },
- {
- label: {
- name: 'BorderDashed',
- },
- value: BorderStyleTypes.DASHED,
- },
- {
- label: {
- name: 'BorderDashDot',
- },
- value: BorderStyleTypes.DOTTED,
- },
- {
- label: {
- name: 'BorderDashDotDot',
- },
- value: BorderStyleTypes.DASH_DOT_DOT,
- },
- {
- label: {
- name: 'BorderMedium',
- },
- value: BorderStyleTypes.MEDIUM,
- },
- {
- label: {
- name: 'BorderMediumDashed',
- },
- value: BorderStyleTypes.MEDIUM_DASHED,
- },
- {
- label: {
- name: 'BorderMediumDashDot',
- },
- value: BorderStyleTypes.MEDIUM_DASH_DOT,
- },
- {
- label: {
- name: 'BorderMediumDashDotDot',
- },
- value: BorderStyleTypes.MEDIUM_DASH_DOT_DOT,
- },
- {
- label: {
- name: 'BorderThick',
- },
- value: BorderStyleTypes.THICK,
- },
-];
-
export const MERGE_CHILDREN = [
{
label: 'merge.all',
@@ -318,117 +170,86 @@ export const MERGE_CHILDREN = [
export const HORIZONTAL_ALIGN_CHILDREN = [
{
label: 'align.left',
- suffix: {
- name: 'LeftAlignIcon',
- },
- value: 1,
+ icon: 'LeftAlignIcon',
+ value: HorizontalAlign.LEFT,
},
{
label: 'align.center',
- selected: true,
- suffix: {
- name: 'CenterAlignIcon',
- },
- value: 2,
+ icon: 'CenterAlignIcon',
+ value: HorizontalAlign.CENTER,
},
{
label: 'align.right',
- suffix: {
- name: 'RightAlignIcon',
- },
- value: 3,
+ icon: 'RightAlignIcon',
+ value: HorizontalAlign.RIGHT,
},
];
export const VERTICAL_ALIGN_CHILDREN = [
{
label: 'align.top',
- suffix: {
- name: 'TopVerticalIcon',
- },
- value: 1,
+ icon: 'TopVerticalIcon',
+ value: VerticalAlign.TOP,
},
{
label: 'align.middle',
- suffix: {
- name: 'CenterVerticalIcon',
- },
- value: 2,
+ icon: 'CenterVerticalIcon',
+ value: VerticalAlign.MIDDLE,
},
{
label: 'align.bottom',
- suffix: {
- name: 'BottomVerticalIcon',
- },
- value: 3,
+ icon: 'BottomVerticalIcon',
+ value: VerticalAlign.BOTTOM,
},
];
export const TEXT_WRAP_CHILDREN = [
{
label: 'textWrap.overflow',
- suffix: {
- name: 'OverflowIcon',
- },
- value: 1,
+ icon: 'OverflowIcon',
+ value: WrapStrategy.OVERFLOW,
},
{
label: 'textWrap.wrap',
- suffix: {
- name: 'BrIcon',
- },
- value: 3,
+ icon: 'BrIcon',
+ value: WrapStrategy.WRAP,
},
{
label: 'textWrap.clip',
- suffix: {
- name: 'CutIcon',
- },
- value: 2,
+ icon: 'CutIcon',
+ value: WrapStrategy.CLIP,
},
];
export const TEXT_ROTATE_CHILDREN = [
{
label: 'textRotate.none',
- suffix: {
- name: 'TextRotateIcon',
- },
+ icon: 'TextRotateIcon',
value: 0,
},
{
label: 'textRotate.angleUp',
- suffix: {
- name: 'TextRotateAngleUpIcon',
- },
+ icon: 'TextRotateAngleUpIcon',
value: -45,
},
{
label: 'textRotate.angleDown',
- suffix: {
- name: 'TextRotateAngleDownIcon',
- },
+ icon: 'TextRotateAngleDownIcon',
value: 45,
},
{
label: 'textRotate.vertical',
- suffix: {
- name: 'TextRotateVerticalIcon',
- },
+ icon: 'TextRotateVerticalIcon',
value: 'v',
},
{
label: 'textRotate.rotationUp',
- suffix: {
- name: 'TextRotateRotationUpIcon',
- },
+ icon: 'TextRotateRotationUpIcon',
value: -90,
},
{
label: 'textRotate.rotationDown',
- suffix: {
- name: 'TextRotateRotationDownIcon',
- },
+ icon: 'TextRotateRotationDownIcon',
value: 90,
},
];
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
index 9a66b57d20..4c2e9a9e15 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
@@ -1,4 +1,4 @@
-import { AppContext, BaseComponentProps, Button, Container, CustomLabel, debounce, IDisplayMenuItem, Select, Tooltip } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, Button, Container, CustomLabel, debounce, IDisplayMenuItem, IMenuItem, Select, Tooltip } from '@univerjs/base-ui';
import { Component, createRef } from 'preact';
import { IToolbarItemProps, SheetContainerUIController } from '../../Controller';
import styles from './index.module.less';
@@ -150,7 +150,7 @@ export class Toolbar extends Component<IProps, IState> {
}
};
- setToolbarNeo = (menuItems: IDisplayMenuItem[]) => {
+ setToolbarNeo = (menuItems: Array<IDisplayMenuItem<IMenuItem>>) => {
this.setState(
{
menuItems,
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
index 0e10bffaa2..22094d4b66 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
@@ -1,7 +1,7 @@
import { ComponentChild, Component } from 'preact';
import { Subscription } from 'rxjs';
-import { AppContext, Button, Tooltip, CustomLabel } from '@univerjs/base-ui';
+import { AppContext, Button, Tooltip, CustomLabel, IDisplayMenuItem, MenuItemType, Select, IMenuSelectorItem, IMenuItem, IMenuButtonItem, IValueOption } from '@univerjs/base-ui';
import { ICommandService } from '@univerjs/core';
import styles from './index.module.less';
@@ -9,21 +9,27 @@ import styles from './index.module.less';
export interface IToolbarItemStatus {
disabled: boolean;
activated: boolean;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ value: any;
}
-export class ToolbarItem extends Component<IDisplayMenuItem, IToolbarItemStatus> {
+/** The component to render toolbar item. */
+export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbarItemStatus> {
static override contextType = AppContext;
private disabledSubscription: Subscription | undefined;
private activatedSubscription: Subscription | undefined;
+ private currentValueSubscription: Subscription | undefined;
+
constructor() {
super();
this.state = {
disabled: false,
activated: false,
+ value: undefined,
};
}
@@ -32,26 +38,79 @@ export class ToolbarItem extends Component<IDisplayMenuItem, IToolbarItemStatus>
this.setState({ disabled });
});
- this.activatedSubscription = this.props.activated$?.subscribe((activated) => {
- this.setState({ activated });
- });
+ if (this.props.type === MenuItemType.BUTTON) {
+ const props = this.props as IDisplayMenuItem<IMenuButtonItem>;
+ this.activatedSubscription = props.activated$?.subscribe((activated) => {
+ this.setState({ activated });
+ });
+ }
+
+ if (this.props.type === MenuItemType.SELECTOR) {
+ const props = this.props as IDisplayMenuItem<IMenuSelectorItem<unknown>>;
+ this.currentValueSubscription = props.value$?.subscribe((value) => {
+ this.setState({ value });
+ });
+ }
}
override componentWillMount() {
this.disabledSubscription?.unsubscribe();
+ this.activatedSubscription?.unsubscribe();
+ this.currentValueSubscription?.unsubscribe();
}
render(): ComponentChild {
- const { props, context } = this;
+ switch (this.props.type) {
+ case MenuItemType.SUBITEMS:
+ case MenuItemType.SELECTOR:
+ return this.renderSelectorType();
+ default:
+ return this.renderButtonType();
+ }
+ }
+
+ private renderSelectorType(): ComponentChild {
+ const { context, state } = this;
const commandService: ICommandService = context.injector.get(ICommandService);
- const { disabled, activated } = this.state;
+ const { disabled, value } = state;
+
+ const props = this.props as IDisplayMenuItem<IMenuSelectorItem<unknown>>;
+ const { icon, title, label, display, selectType, selections, id } = props;
return (
- <Tooltip title={props.title + (props.shortcut ? ` (${props.shortcut})` : '')} placement="bottom">
+ <Tooltip title={this.getTooltip()} placement="bottom">
+ <Select
+ id={id}
+ title={title}
+ children={selections!}
+ options={selections as IValueOption[]}
+ display={display}
+ icon={icon}
+ value={value}
+ label={value ?? label} // TODO: this line is strange
+ onClick={(value) => commandService.executeCommand(id, { value })} // TODO@wzhudev: should be merged to a single API on value change
+ onPressEnter={(value) => commandService.executeCommand(id, { value })}
+ type={selectType!}
+ ></Select>
+ </Tooltip>
+ );
+ }
+
+ private renderButtonType(): ComponentChild {
+ const { props, context, state } = this;
+ const { disabled, activated } = state;
+ const commandService: ICommandService = context.injector.get(ICommandService);
+
+ return (
+ <Tooltip title={this.getTooltip()} placement="bottom">
<Button active={activated} className={styles.textButton} type="text" disabled={disabled} onClick={() => commandService.executeCommand(props.id)}>
<CustomLabel label={{ name: props.icon }} />
</Button>
</Tooltip>
);
}
+
+ private getTooltip(): string {
+ return this.context.localeService?.t(this.props.tooltip) + (this.props.shortcut ? ` (${this.props.shortcut})` : '');
+ }
}
diff --git a/packages/ui-plugin-slides/package.json b/packages/ui-plugin-slides/package.json
index 2ff5e8cc52..10a9f997af 100644
--- a/packages/ui-plugin-slides/package.json
+++ b/packages/ui-plugin-slides/package.json
@@ -59,6 +59,6 @@
"@univerjs/core": "workspace:^0.0.1",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1",
- "@wendellhu/redi": "^0.12.6"
+ "@wendellhu/redi": "^0.12.7"
}
}
\ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 712fcaeb46..5dcc59975a 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -594,8 +594,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -640,8 +640,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
preact:
specifier: ^10.12.1
version: 10.17.1
@@ -720,8 +720,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
devDependencies:
'@testing-library/preact':
specifier: ^2.0.1
@@ -769,8 +769,11 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
devDependencies:
'@testing-library/preact':
specifier: ^2.0.1
@@ -821,8 +824,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -870,8 +873,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
preact:
specifier: ^10.12.1
version: 10.17.1
@@ -1011,8 +1014,8 @@ importers:
packages/core:
dependencies:
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
dayjs:
specifier: ^1.11.5
version: 1.11.5
@@ -1133,8 +1136,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
preact:
specifier: ^10.12.1
version: 10.17.1
@@ -1194,8 +1197,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
preact:
specifier: ^10.12.1
version: 10.17.1
@@ -1255,8 +1258,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
preact:
specifier: ^10.12.1
version: 10.17.1
@@ -1316,8 +1319,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
luckyexcel:
specifier: ^1.0.1
version: 1.0.1
@@ -1374,8 +1377,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
preact:
specifier: ^10.12.1
version: 10.17.1
@@ -1444,8 +1447,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
preact:
specifier: ^10.12.1
version: 10.17.1
@@ -1487,8 +1490,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -1545,8 +1548,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -1597,8 +1600,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -1876,6 +1879,7 @@ packages:
resolution: {integrity: sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1887,6 +1891,7 @@ packages:
resolution: {integrity: sha512-1auuwmK+Rz13SJj36R+jqFPMJWyKEDd7lLSdOj4oJK0UTgGueSAtkrCvz9ewmgyU/P941Rv2fQwZJN8s6QruXw==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-dynamic-import instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1898,6 +1903,7 @@ packages:
resolution: {integrity: sha512-k1NtHyOMvlDDFeb9G5PhUXuGj8m/wiwojgQVEhJ/fsVsMCpLyOP4h0uGEjYJKrRI+EVPlb5Jk+Gt9P97lOGwtA==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1909,6 +1915,7 @@ packages:
resolution: {integrity: sha512-y7C7cZgpMIjWlKE5T7eJwp+tnRYM89HmRvWM5EQuB5BoHEONjmQ8lSNmBUwOyy/GFRsohJED51YBF79hE1djug==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1920,6 +1927,7 @@ packages:
resolution: {integrity: sha512-wQxQzxYeJqHcfppzBDnm1yAY0jSRkUXR2z8RePZYrKwMKgMlE8+Z6LUno+bd6LvbGh8Gltvy74+9pIYkr+XkKA==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1931,6 +1939,7 @@ packages:
resolution: {integrity: sha512-ozlZFogPqoLm8WBr5Z8UckIoE4YQ5KESVcNudyXOR8uqIkliTEgJ3RoketfG6pmzLdeZF0H/wjE9/cCEitBl7Q==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1942,6 +1951,7 @@ packages:
resolution: {integrity: sha512-p4zeefM72gpmEe2fkUr/OnOXpWEf8nAgk7ZYVqqfFiyIG7oFfVZcCrU64hWn5xp4tQ9LkV4bTIa5rD0KANpKNA==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1954,6 +1964,7 @@ packages:
resolution: {integrity: sha512-nutsvktDItsNn4rpGItSNV2sz1XwS+nfU0Rg8aCx3W3NOKVzdMjJRu0O5OkgDp3ZGICSTbgRpxZoWsxoKRvbeA==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-methods instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -1965,6 +1976,7 @@ packages:
resolution: {integrity: sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==}
engines: {node: '>=6.9.0'}
+ deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.
peerDependencies:
'@babel/core': ^7.0.0-0
dependencies:
@@ -2528,13 +2540,13 @@ packages:
'@types/node': 20.4.7
chalk: 4.1.2
cosmiconfig: 8.2.0
- cosmiconfig-typescript-loader: 4.4.0(@types/[email protected])([email protected])([email protected])([email protected])
+ cosmiconfig-typescript-loader: 4.4.0(@types/[email protected])([email protected])([email protected])([email protected])
lodash.isplainobject: 4.0.6
lodash.merge: 4.6.2
lodash.uniq: 4.5.0
resolve-from: 5.0.0
- ts-node: 10.9.1(@types/[email protected])([email protected])
- typescript: 4.7.4
+ ts-node: 10.9.1(@types/[email protected])([email protected])
+ typescript: 4.9.5
transitivePeerDependencies:
- '@swc/core'
- '@swc/wasm'
@@ -3591,7 +3603,7 @@ packages:
resolution: {integrity: sha512-mki5uBvhHzO8kYYix/WRy2WX8S3B5wdVSc9D6KcU5lQNglP2yt58/VfLuAK49glRXChosY8ap2oJ1qgma3GUVA==}
dependencies:
'@babel/runtime': 7.22.11
- '@types/node': 12.20.24
+ '@types/node': 12.20.55
find-up: 4.1.0
fs-extra: 8.1.0
dev: true
@@ -4137,6 +4149,10 @@ packages:
resolution: {integrity: sha512-yxDeaQIAJlMav7fH5AQqPH1u8YIuhYJXYBzxaQ4PifsU0GDO38MSdmEDeRlIxrKbC6NbEaaEHDanWb+y30U8SQ==}
dev: true
+ resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==}
+ dev: true
+
resolution: {integrity: sha512-FKyawK3o5KL16AwbeFajen8G4K3mmqUrQsehn5wNKs8IzlKHE8TfnSmILXVMVziAEcnB23u1RCFU1NT6hSyr7Q==}
dev: true
@@ -4366,8 +4382,8 @@ packages:
vite: 2.4.4
dev: true
- /@wendellhu/[email protected]:
- resolution: {integrity: sha512-mrYQUPUoCsR1YOS+Ze8T9vKGVbF6KCxXJ/gTb/MnREKOtgiuyp204B8/wFXLO452u9Vl9Apazitdip4g7wsJFw==}
+ /@wendellhu/[email protected]:
+ resolution: {integrity: sha512-HAJhOfAqD1E7O/FGEnz27psFjDq6h3xBbmN9b/j2ijAslleb71WLnHUrhRtMCgIWEm7Ktb8fkk0aK80pJsTlng==}
dev: false
@@ -4802,7 +4818,7 @@ packages:
hasBin: true
dependencies:
caniuse-lite: 1.0.30001525
- electron-to-chromium: 1.4.506
+ electron-to-chromium: 1.4.508
node-releases: 2.0.13
update-browserslist-db: 1.0.11([email protected])
dev: true
@@ -5200,7 +5216,7 @@ packages:
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
dev: false
resolution: {integrity: sha512-BabizFdC3wBHhbI4kJh0VkQP9GkBfoHPydD0COMce1nJ1kJAB3F2TmJ/I7diULBKtmEWSwEbuN/KDtgnmUUVmw==}
engines: {node: '>=v14.21.3'}
peerDependencies:
@@ -5211,8 +5227,8 @@ packages:
dependencies:
'@types/node': 20.4.7
cosmiconfig: 8.2.0
- ts-node: 10.9.1(@types/[email protected])([email protected])
- typescript: 4.7.4
+ ts-node: 10.9.1(@types/[email protected])([email protected])
+ typescript: 4.9.5
dev: true
@@ -5615,8 +5631,8 @@ packages:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
dev: true
- resolution: {integrity: sha512-xxGct4GPAKSRlrLBtJxJFYy74W11zX6PO9GyHgl/U+2s3Dp0ZEwAklDfNHXOWcvH7zWMpsmgbR0ggEuaYAVvHA==}
+ resolution: {integrity: sha512-FFa8QKjQK/A5QuFr2167myhMesGrhlOBD+3cYNxO9/S4XzHEXesyTD/1/xF644gC8buFPz3ca6G1LOQD0tZrrg==}
dev: true
@@ -8097,8 +8113,8 @@ packages:
resolution: {integrity: sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==}
dev: true
- resolution: {integrity: sha512-hrazgRSlhzacZ69LdcKfhi3Vu13z2yFfoAzmEov3yFIJlatTdVGUW6vle1zjH8qkzdCn/qGw8rapjqsObbYXAg==}
+ resolution: {integrity: sha512-vIiDxQKmRidUVp8KngT8MZSOcmRVm2zV7jbMjNYWuHcJWI0bUck3nRTGQjhpPlQenIQIBC5Vp9AhcnHbWQqafw==}
dependencies:
'@hapi/hoek': 9.3.0
'@hapi/topo': 5.1.0
@@ -10820,7 +10836,7 @@ packages:
yn: 3.1.1
dev: true
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
hasBin: true
peerDependencies:
@@ -10846,7 +10862,7 @@ packages:
create-require: 1.1.1
diff: 4.0.2
make-error: 1.3.6
- typescript: 4.7.4
+ typescript: 4.9.5
v8-compile-cache-lib: 3.0.1
yn: 3.1.1
dev: true
@@ -11054,6 +11070,12 @@ packages:
hasBin: true
dev: true
+ resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==}
+ engines: {node: '>=4.2.0'}
+ hasBin: true
+ dev: true
+
resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==}
dependencies:
@@ -11204,7 +11226,7 @@ packages:
hasBin: true
dependencies:
axios: 0.25.0([email protected])
- joi: 17.10.0
+ joi: 17.10.1
lodash: 4.17.21
minimist: 1.2.8
rxjs: 7.8.1