Skip to content

Commit

Permalink
feat: add menu for auto-col
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Oct 18, 2024
1 parent 55db84e commit 0629d61
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ export function getDocsSkeletonPageSize(documentSkeleton: DocumentSkeleton, angl
height: allRotatedHeight,
};
}
if (typeof window !== 'undefined') {
window.getDocsSkeletonPageSize = getDocsSkeletonPageSize;
}

interface ICellOtherConfig {
/**
* textRotation
Expand Down
7 changes: 6 additions & 1 deletion packages/sheets-ui/src/controllers/menu.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -105,6 +105,7 @@ import {
BackgroundColorSelectorMenuItemFactory,
BoldMenuItemFactory,
CancelFrozenMenuItemFactory,
ColAutoWidthMenuItemFactory,
CopyMenuItemFactory,
// CutMenuItemFactory,
FitContentMenuItemFactory,
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 16 additions & 4 deletions packages/sheets-ui/src/controllers/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -56,6 +58,7 @@ import {
SetTextWrapCommand,
SetVerticalTextAlignCommand,
SetWorksheetActiveOperation,
SetWorksheetColIsAutoWidthCommand,
SetWorksheetColWidthMutation,
SetWorksheetRowIsAutoHeightCommand,
SetWorksheetRowIsAutoHeightMutation,
Expand All @@ -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,
Expand Down Expand Up @@ -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<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/sheets-ui/src/locale/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,4 +627,3 @@ const locale: typeof zhCN = {
},
};
export default locale;

Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/sheets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export {
export {
DeltaColumnWidthCommand,
type IDeltaColumnWidthCommandParams,
type ISetWorksheetColIsAutoWidthCommandParams,
SetColWidthCommand,
SetWorksheetColIsAutoWidthCommand,
} from './commands/commands/set-worksheet-col-width.command';
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/common/component-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
AllBorderSingle,
AmplifySingle,
AutoHeight,
AutoWidth,
AutowrapSingle,
AvgSingle,
BackSlashSingle,
Expand Down Expand Up @@ -220,6 +221,7 @@ export class ComponentManager {
Hide,
HorizontalBorder,
AutoHeight,
AutoWidth,
AdjustHeight,
AdjustWidth,
AvgSingle,
Expand Down

0 comments on commit 0629d61

Please sign in to comment.