From 0629d6121468b5baa3c9a74f75719ee828c3df53 Mon Sep 17 00:00:00 2001 From: lumixraku Date: Fri, 18 Oct 2024 17:25:23 +0800 Subject: [PATCH] feat: add menu for auto-col --- .../src/components/sheets/extensions/font.ts | 2 -- .../src/components/sheets/sheet-skeleton.ts | 4 +--- .../sheets-ui/src/controllers/menu.schema.ts | 7 ++++++- .../sheets-ui/src/controllers/menu/menu.ts | 20 +++++++++++++++---- .../header-resize.render-controller.ts | 3 +-- .../sheet.render-controller.ts | 1 - packages/sheets-ui/src/locale/zh-TW.ts | 1 - .../set-worksheet-row-height.command.ts | 2 -- packages/sheets/src/index.ts | 1 + packages/ui/src/common/component-manager.ts | 2 ++ 10 files changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.ts index 9a1076e5e96..411fd67d506 100644 --- a/packages/engine-render/src/components/sheets/extensions/font.ts +++ b/packages/engine-render/src/components/sheets/extensions/font.ts @@ -340,8 +340,6 @@ export class Font extends SheetExtension { const cellHeight = endY - startY; const cellWidth = endX - startX; - console.log('rs', row, col, window.getDocsSkeletonPageSize(documentSkeleton)); - // WRAP means next line if (wrapStrategy === WrapStrategy.WRAP && vertexAngle === 0) { documentSkeleton.getViewModel().getDataModel().updateDocumentDataPageSize(cellWidth); diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.ts index 0a5d2e6ea30..2ed47561076 100644 --- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts +++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts @@ -172,9 +172,7 @@ export function getDocsSkeletonPageSize(documentSkeleton: DocumentSkeleton, angl height: allRotatedHeight, }; } -if (typeof window !== 'undefined') { - window.getDocsSkeletonPageSize = getDocsSkeletonPageSize; -} + interface ICellOtherConfig { /** * textRotation diff --git a/packages/sheets-ui/src/controllers/menu.schema.ts b/packages/sheets-ui/src/controllers/menu.schema.ts index 3d218ac81b3..5af48d1c106 100644 --- a/packages/sheets-ui/src/controllers/menu.schema.ts +++ b/packages/sheets-ui/src/controllers/menu.schema.ts @@ -39,7 +39,7 @@ import { SetSelectedRowsVisibleCommand, SetTabColorCommand, SetTextRotationCommand, SetTextWrapCommand, - SetVerticalTextAlignCommand, SetWorksheetHideCommand, + SetVerticalTextAlignCommand, SetWorksheetColIsAutoWidthCommand, SetWorksheetHideCommand, SetWorksheetRowIsAutoHeightCommand, } from '@univerjs/sheets'; import { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui'; @@ -105,6 +105,7 @@ import { BackgroundColorSelectorMenuItemFactory, BoldMenuItemFactory, CancelFrozenMenuItemFactory, + ColAutoWidthMenuItemFactory, CopyMenuItemFactory, // CutMenuItemFactory, FitContentMenuItemFactory, @@ -484,6 +485,10 @@ export const menuSchema: MenuSchemaType = { order: 3, menuItemFactory: SetColWidthMenuItemFactory, }, + [SetWorksheetColIsAutoWidthCommand.id]: { + order: 4, + menuItemFactory: ColAutoWidthMenuItemFactory, + }, [SHEET_FROZEN_HEADER_MENU_ID]: { order: 4, menuItemFactory: SheetFrozenHeaderMenuItemFactory, diff --git a/packages/sheets-ui/src/controllers/menu/menu.ts b/packages/sheets-ui/src/controllers/menu/menu.ts index 7f0cd74b35c..02797dd9b8d 100644 --- a/packages/sheets-ui/src/controllers/menu/menu.ts +++ b/packages/sheets-ui/src/controllers/menu/menu.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import type { IAccessor } from '@univerjs/core'; +import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui'; import { BooleanNumber, DEFAULT_STYLES, @@ -32,9 +34,9 @@ import { VerticalAlign, WrapStrategy, } from '@univerjs/core'; + import { DocSelectionManagerService, SetTextSelectionsOperation } from '@univerjs/docs'; import { SetInlineFormatCommand } from '@univerjs/docs-ui'; - import { RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, @@ -56,6 +58,7 @@ import { SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetActiveOperation, + SetWorksheetColIsAutoWidthCommand, SetWorksheetColWidthMutation, SetWorksheetRowIsAutoHeightCommand, SetWorksheetRowIsAutoHeightMutation, @@ -77,10 +80,8 @@ import { IClipboardInterfaceService, MenuItemType, } from '@univerjs/ui'; -import { combineLatestWith, map, Observable } from 'rxjs'; -import type { IAccessor } from '@univerjs/core'; -import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui'; +import { combineLatestWith, map, Observable } from 'rxjs'; import { SheetCopyCommand, SheetCutCommand, @@ -983,6 +984,17 @@ export function FitContentMenuItemFactory(accessor: IAccessor): IMenuButtonItem }; } +export function ColAutoWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem { + return { + id: SetWorksheetColIsAutoWidthCommand.id, + type: MenuItemType.BUTTON, + icon: 'AutoWidth', + title: 'rightClick.fitContent', + disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetRowStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), + hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), + }; +} + export const SHEET_FROZEN_MENU_ID = 'sheet.menu.sheet-frozen'; export function SheetFrozenMenuItemFactory(accessor: IAccessor): IMenuSelectorItem { diff --git a/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts index 9c6395a27a3..8da1f01ec3a 100644 --- a/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts +++ b/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts @@ -34,9 +34,8 @@ import { toDisposable, } from '@univerjs/core'; import { CURSOR_TYPE, Rect, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render'; -import { DeltaColumnWidthCommand, DeltaRowHeightCommand, SetWorksheetRowIsAutoHeightCommand } from '@univerjs/sheets'; +import { DeltaColumnWidthCommand, DeltaRowHeightCommand, SetWorksheetColIsAutoWidthCommand, SetWorksheetRowIsAutoHeightCommand } from '@univerjs/sheets'; -import { SetWorksheetColIsAutoWidthCommand } from '@univerjs/sheets/commands/commands/set-worksheet-col-width.command.js'; import { Subscription } from 'rxjs'; import { SHEET_COMPONENT_HEADER_LAYER_INDEX, SHEET_VIEW_KEY } from '../../common/keys'; import { SheetSkeletonManagerService } from '../../services/sheet-skeleton-manager.service'; diff --git a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts index 21d93efc713..8fca0ef8be5 100644 --- a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts +++ b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts @@ -244,7 +244,6 @@ export class SheetRenderController extends RxDisposable implements IRenderModule const bufferEdgeX = 100; const bufferEdgeY = 100; - window.sc = scene; const viewMain = new Viewport(SHEET_VIEWPORT_KEY.VIEW_MAIN, scene, { left: rowHeader.width, top: columnHeader.height, diff --git a/packages/sheets-ui/src/locale/zh-TW.ts b/packages/sheets-ui/src/locale/zh-TW.ts index 7a674a6a9b3..fec21a284f0 100644 --- a/packages/sheets-ui/src/locale/zh-TW.ts +++ b/packages/sheets-ui/src/locale/zh-TW.ts @@ -627,4 +627,3 @@ const locale: typeof zhCN = { }, }; export default locale; - diff --git a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts index 2ef4c4ca3eb..3c2c53e10ac 100644 --- a/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts +++ b/packages/sheets/src/commands/commands/set-worksheet-row-height.command.ts @@ -292,8 +292,6 @@ export interface ISetWorksheetRowIsAutoHeightCommandParams { ranges?: IRange[]; // For Facade API } - - export const SetWorksheetRowIsAutoHeightCommand: ICommand = { type: CommandType.COMMAND, id: 'sheet.command.set-row-is-auto-height', diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts index 7933546792a..6a237917a32 100644 --- a/packages/sheets/src/index.ts +++ b/packages/sheets/src/index.ts @@ -284,6 +284,7 @@ export { export { DeltaColumnWidthCommand, type IDeltaColumnWidthCommandParams, + type ISetWorksheetColIsAutoWidthCommandParams, SetColWidthCommand, SetWorksheetColIsAutoWidthCommand, } from './commands/commands/set-worksheet-col-width.command'; diff --git a/packages/ui/src/common/component-manager.ts b/packages/ui/src/common/component-manager.ts index 6eab0800328..9f11c43a4ce 100644 --- a/packages/ui/src/common/component-manager.ts +++ b/packages/ui/src/common/component-manager.ts @@ -29,6 +29,7 @@ import { AllBorderSingle, AmplifySingle, AutoHeight, + AutoWidth, AutowrapSingle, AvgSingle, BackSlashSingle, @@ -220,6 +221,7 @@ export class ComponentManager { Hide, HorizontalBorder, AutoHeight, + AutoWidth, AdjustHeight, AdjustWidth, AvgSingle,