Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
chore: update code styles
Wenzhao Hu853e8a05bfa6
diff --git a/packages/core/src/services/command/command.service.ts b/packages/core/src/services/command/command.service.tsindex 359f7b571e..159d4923c6 100644--- a/packages/core/src/services/command/command.service.ts+++ b/packages/core/src/services/command/command.service.ts@@ -322,7 +322,7 @@ export class CommandService implements ICommandService {): Promise<R> {this._log.log('[CommandService]',- `${'|-'.repeat(this._commandExecutingLevel)}executing command "${command.id}"`+ `${'|-'.repeat(Math.max(this._commandExecutingLevel, 0))}executing command "${command.id}"`);this._commandExecutingLevel++;@@ -342,7 +342,7 @@ export class CommandService implements ICommandService {private _syncExecute<P extends object, R = boolean>(command: ICommand<P, R>, injector: Injector, params?: P): R {this._log.log('[CommandService]',- `${'|-'.repeat(this._commandExecutingLevel)}executing command "${command.id}"`+ `${'|-'.repeat(Math.max(0, this._commandExecutingLevel))}executing command "${command.id}"`);this._commandExecutingLevel++;diff --git a/packages/core/src/services/theme/theme.service.ts b/packages/core/src/services/theme/theme.service.tsindex 3442bded2d..add0ece73f 100644--- a/packages/core/src/services/theme/theme.service.ts+++ b/packages/core/src/services/theme/theme.service.ts@@ -13,15 +13,12 @@ export class ThemeService extends Disposable {// TODO: dark modeprivate darkMode: boolean = false;- readonly currentTheme$: Observable<IStyleSheet>;-private readonly _currentTheme$ = new BehaviorSubject<IStyleSheet>({});+ readonly currentTheme$: Observable<IStyleSheet> = this._currentTheme$.asObservable();constructor() {super();- this.currentTheme$ = this._currentTheme$.asObservable();-this.disposeWithMe(toDisposable(() => this._currentTheme$.complete()));}diff --git a/packages/ui-plugin-sheets/src/common/keys.ts b/packages/ui-plugin-sheets/src/common/keys.tsindex 57c78ceef0..38c1a0f743 100644--- a/packages/ui-plugin-sheets/src/common/keys.ts+++ b/packages/ui-plugin-sheets/src/common/keys.ts@@ -26,3 +26,5 @@ export const SHEET_COMPONENT_HEADER_LAYER_INDEX = 2;export const SHEET_ZOOM_RANGE = [10, 400];export const SHEET_COMPONENT_UNHIDE_LAYER_INDEX = 1001;++// TODO@wzhudev: there should be a global zIndex layer fo sheet selectionsdiff --git a/packages/ui-plugin-sheets/src/controllers/header-unhide.controller.ts b/packages/ui-plugin-sheets/src/controllers/header-unhide.controller.tsindex 04820cf771..0dbcc08c7e 100644--- a/packages/ui-plugin-sheets/src/controllers/header-unhide.controller.ts+++ b/packages/ui-plugin-sheets/src/controllers/header-unhide.controller.ts@@ -25,7 +25,7 @@ import { takeUntil } from 'rxjs';import { SHEET_COMPONENT_UNHIDE_LAYER_INDEX } from '../common/keys';import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';-import { HeaderUnhideShape, HeaderUnhideShapeType } from '../views/header-unhide-shape';+import { HeaderUnhideShape, HeaderUnhideShapeType, UNHIDE_ICON_SIZE } from '../views/header-unhide-shape';import { getCoordByCell, getSheetObject } from './utils/component-tools';const HEADER_UNHIDE_CONTROLLER_SHAPE = '__SpreadsheetHeaderUnhideSHAPEControllerShape__';@@ -48,7 +48,7 @@ export class HeaderUnhideController extends RxDisposable {constructor(@Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,@ICommandService private readonly _cmdSrv: ICommandService,- @IUniverInstanceService private readonly _cuSrv: IUniverInstanceService,+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@IRenderManagerService private readonly _rendererManagerService: IRenderManagerService) {super();@@ -61,29 +61,28 @@ export class HeaderUnhideController extends RxDisposable {}private _init(): void {- // First just let me render a unhide button of the column header!.const sheetObject = this._getSheetObject();if (!sheetObject) {return;}- // try to render the unhide button for the current worksheet- const workbook = this._cuSrv.getCurrentUniverSheetInstance();+ // Try to render the unhide button for the current worksheet.+ const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();const worksheet = workbook.getActiveSheet();if (worksheet) {this._initForWorksheet(workbook, worksheet);}- // re-render when sheet skeleton is changed+ // Re-render when sheet skeleton changes.this._sheetSkeletonManagerService.currentSkeleton$.pipe(takeUntil(this.dispose$)).subscribe((skeleton) => {if (skeleton) {- const workbook = this._cuSrv.getUniverSheetInstance(skeleton.unitId)!;+ const workbook = this._univerInstanceService.getUniverSheetInstance(skeleton.unitId)!;const worksheet = workbook.getSheetBySheetId(skeleton.sheetId)!;this._updateWorksheet(workbook!, worksheet);}});- // re-render hidden rows / cols when specific commands are executed+ // Re-render hidden rows / cols when specific commands are executed.this.disposeWithMe(this._cmdSrv.onCommandExecuted((command) => {if (@@ -95,7 +94,9 @@ export class HeaderUnhideController extends RxDisposable {return;}- const workbook = this._cuSrv.getUniverSheetInstance((command.params as IKeyValue).workbookId);+ const workbook = this._univerInstanceService.getUniverSheetInstance(+ (command.params as IKeyValue).workbookId+ );const worksheet = workbook?.getSheetBySheetId((command.params as IKeyValue).worksheetId);if (worksheet) {this._updateWorksheet(workbook!, worksheet);@@ -138,8 +139,8 @@ export class HeaderUnhideController extends RxDisposable {hovered: false,hasPrevious,hasNext,- top: position.startY - (hasPrevious ? 12 : 0),- left: position.startX - 12,+ top: position.startY - (hasPrevious ? UNHIDE_ICON_SIZE : 0),+ left: position.startX - UNHIDE_ICON_SIZE,},() =>this._cmdSrv.executeCommand<ISetSpecificRowsVisibleCommandParams>(@@ -165,8 +166,9 @@ export class HeaderUnhideController extends RxDisposable {hovered: false,hasPrevious,hasNext,- left: position.startX - (hasPrevious ? 12 : 0),- top: 20 - 12,+ left: position.startX - (hasPrevious ? UNHIDE_ICON_SIZE : 0),+ // eslint-disable-next-line no-magic-numbers+ top: 20 - UNHIDE_ICON_SIZE,},() =>this._cmdSrv.executeCommand<ISetSpecificColsVisibleCommandParams>(@@ -193,6 +195,6 @@ export class HeaderUnhideController extends RxDisposable {}private _getSheetObject() {- return getSheetObject(this._cuSrv, this._rendererManagerService);+ return getSheetObject(this._univerInstanceService, this._rendererManagerService);}}diff --git a/packages/ui-plugin-sheets/src/controllers/selection.controller.ts b/packages/ui-plugin-sheets/src/controllers/selection.controller.tsindex df024512cf..adc5e44f42 100644--- a/packages/ui-plugin-sheets/src/controllers/selection.controller.ts+++ b/packages/ui-plugin-sheets/src/controllers/selection.controller.ts@@ -45,36 +45,24 @@ export class SelectionController extends Disposable {private _initialize() {const workbook = this._currentUniverService.getCurrentUniverSheetInstance();const worksheet = workbook.getActiveSheet();-const sheetObject = this._getSheetObject();if (sheetObject == null) {return;}- const { spreadsheetLeftTopPlaceholder } = sheetObject;-- this._onChangeListener();-- this._initialMain(sheetObject);-- this._themeChangeListener();-- this._initialRowHeader(sheetObject);-- this._initialColumnHeader(sheetObject);+ // TODO@wzhudev: listen clicking event on the top-left corner to select all cells.- this._skeletonListener();-- this._commandExecutedListener();-- this.disposeWithMe(toDisposable(spreadsheetLeftTopPlaceholder?.onPointerDownObserver.add(() => {})));-- this._userActionSyncListener();+ this._initViewMainListener(sheetObject);+ this._initRowHeader(sheetObject);+ this._initColumnHeader(sheetObject);+ this._initSelectionChangeListener();+ this._initThemeChangeListener();+ this._initSkeletonChangeListener();+ this._initCommandListener();+ this._initUserActionSyncListener();const unitId = workbook.getUnitId();-const sheetId = worksheet.getSheetId();-this._selectionManagerService.setCurrentSelection({pluginName: NORMAL_SELECTION_PLUGIN_NAME,unitId,@@ -82,7 +70,7 @@ export class SelectionController extends Disposable {});}- private _initialMain(sheetObject: ISheetObjectParam) {+ private _initViewMainListener(sheetObject: ISheetObjectParam) {const { spreadsheet, scene } = sheetObject;const viewportMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);this.disposeWithMe(@@ -105,7 +93,7 @@ export class SelectionController extends Disposable {);}- private _themeChangeListener() {+ private _initThemeChangeListener() {this.disposeWithMe(toDisposable(this._themeService.currentTheme$.subscribe(() => {@@ -130,7 +118,7 @@ export class SelectionController extends Disposable {);}- private _initialRowHeader(sheetObject: ISheetObjectParam) {+ private _initRowHeader(sheetObject: ISheetObjectParam) {const { spreadsheetRowHeader, spreadsheet, scene } = sheetObject;const viewportMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);this.disposeWithMe(@@ -153,7 +141,7 @@ export class SelectionController extends Disposable {// spreadsheetRowHeader?.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent, state) => {});}- private _initialColumnHeader(sheetObject: ISheetObjectParam) {+ private _initColumnHeader(sheetObject: ISheetObjectParam) {const { spreadsheetColumnHeader, spreadsheet, scene } = sheetObject;const viewportMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);this.disposeWithMe(@@ -174,7 +162,7 @@ export class SelectionController extends Disposable {);}- private _onChangeListener() {+ private _initSelectionChangeListener() {this.disposeWithMe(toDisposable(this._selectionManagerService.selectionInfo$.subscribe((param) => {@@ -196,7 +184,7 @@ export class SelectionController extends Disposable {);}- private _userActionSyncListener() {+ private _initUserActionSyncListener() {this._selectionRenderService.selectionRangeWithStyle$.subscribe((selectionDataWithStyleList) => {const workbook = this._currentUniverService.getCurrentUniverSheetInstance();const unitId = workbook.getUnitId();@@ -222,7 +210,7 @@ export class SelectionController extends Disposable {return getSheetObject(this._currentUniverService, this._renderManagerService);}- private _commandExecutedListener() {+ private _initCommandListener() {const updateCommandList = [SetZoomRatioOperation.id];this.disposeWithMe(@@ -243,7 +231,7 @@ export class SelectionController extends Disposable {);}- private _skeletonListener() {+ private _initSkeletonChangeListener() {this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {if (param == null) {return;diff --git a/packages/ui-plugin-sheets/src/index.ts b/packages/ui-plugin-sheets/src/index.tsindex b9904c4dd8..41cdff2eca 100644--- a/packages/ui-plugin-sheets/src/index.ts+++ b/packages/ui-plugin-sheets/src/index.ts@@ -1,10 +1,17 @@export * from './Basics';export { SetCellEditVisibleArrowOperation } from './commands/operations/cell-edit.operation';export { CellEditorManagerService, ICellEditorManagerService } from './services/editor/cell-editor-manager.service';+export {+ getCoordByCell,+ getCoordByOffset,+ getSheetObject,+ getTransformCoord,+} from './controllers/utils/component-tools';export {EditorBridgeService,IEditorBridgeService,type IEditorBridgeServiceVisibleParam,} from './services/editor-bridge.service';export { ISelectionRenderService } from './services/selection/selection-render.service';+export { SheetSkeletonManagerService } from './services/sheet-skeleton-manager.service';export { SheetUIPlugin } from './sheet-ui-plugin';diff --git a/packages/ui-plugin-sheets/src/services/selection/selection-render.service.ts b/packages/ui-plugin-sheets/src/services/selection/selection-render.service.tsindex 76dfbd8edc..13a1f15c2e 100644--- a/packages/ui-plugin-sheets/src/services/selection/selection-render.service.ts+++ b/packages/ui-plugin-sheets/src/services/selection/selection-render.service.ts@@ -14,8 +14,6 @@ import {ISelectionWithStyle,} from '@univerjs/base-sheets/Basics/selection.js';import {- DEFAULT_WORKSHEET_COLUMN_COUNT,- DEFAULT_WORKSHEET_ROW_COUNT,IRange,IRangeWithCoord,ISelectionCell,@@ -46,18 +44,10 @@ export interface ISelectionRenderService {enableSelection(): void;disableSelection(): void;- getViewPort(): Viewport;-addControlToCurrentByRangeData(data: ISelectionWithCoordAndStyle): void;changeRuntime(skeleton: SpreadsheetSkeleton, scene: Scene, viewport?: Viewport): void;- // getSpreadsheet(): void;- // getMaxIndex(): void;- getScene(): void;- getSkeleton(): void;- getRowAndColumnCount(): void;+ getViewPort(): Viewport;getCurrentControls(): SelectionShape[];- getCurrentControl(): void;- clearSelectionControls(): void;getActiveRangeList(): Nullable<IRange[]>;getActiveRange(): Nullable<IRange>;getActiveSelection(): Nullable<SelectionShape>;@@ -207,7 +197,7 @@ export class SelectionRenderService implements ISelectionRenderService {style = getNormalSelectionStyle(this._themeService);}- const scene = this.getScene();+ const scene = this._scene;if (scene == null || skeleton == null) {return;@@ -237,30 +227,6 @@ export class SelectionRenderService implements ISelectionRenderService {this._activeViewport = viewport || scene.getViewports()[0];}- // getSpreadsheet() {- // return this._sheetComponent;- // }-- // getMaxIndex() {- // return this._sheetComponent.zIndex + 1;- // }-- getScene() {- return this._scene;- }-- getSkeleton() {- return this._skeleton;- }-- getRowAndColumnCount() {- const skeleton = this.getSkeleton();- return {- rowCount: skeleton?.getRowCount() || DEFAULT_WORKSHEET_ROW_COUNT,- columnCount: skeleton?.getColumnCount() || DEFAULT_WORKSHEET_COLUMN_COUNT,- };- }-getSelectionDataWithStyle() {const selectionControls = this._selectionControls;return selectionControls.map((control) => control.getValue());@@ -270,7 +236,7 @@ export class SelectionRenderService implements ISelectionRenderService {return this._selectionControls;}- getCurrentControl() {+ private _getCurrentControl() {const controls = this.getCurrentControls();if (controls && controls.length > 0) {for (const control of controls) {@@ -282,7 +248,7 @@ export class SelectionRenderService implements ISelectionRenderService {}}- clearSelectionControls() {+ private _clearSelectionControls() {const curControls = this.getCurrentControls();if (curControls.length > 0) {@@ -348,7 +314,7 @@ export class SelectionRenderService implements ISelectionRenderService {}reset() {- this.clearSelectionControls();+ this._clearSelectionControls();this._moveObserver = null;this._upObserver = null;this._downObserver = null;@@ -381,7 +347,7 @@ export class SelectionRenderService implements ISelectionRenderService {const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;- const scene = this.getScene();+ const scene = this._scene;if (scene == null || skeleton == null) {return;@@ -434,7 +400,7 @@ export class SelectionRenderService implements ISelectionRenderService {this._startSelectionRange = startSelectionRange;- let selectionControl: Nullable<SelectionShape> = this.getCurrentControl();+ let selectionControl: Nullable<SelectionShape> = this._getCurrentControl();const curControls = this.getCurrentControls();@@ -523,7 +489,7 @@ export class SelectionRenderService implements ISelectionRenderService {scene.disableEvent();- const scrollTimer = ScrollTimer.create(this.getScene());+ const scrollTimer = ScrollTimer.create(this._scene);scrollTimer.startScroll(newEvtOffsetX, newEvtOffsetY, viewport);this._scrollTimer = scrollTimer;@@ -579,8 +545,8 @@ export class SelectionRenderService implements ISelectionRenderService {convertRangeDataToSelection(range: IRange): Nullable<IRangeWithCoord> {const { startRow, startColumn, endRow, endColumn, rangeType } = range;- const scene = this.getScene();- const skeleton = this.getSkeleton();+ const scene = this._scene;+ const skeleton = this._skeleton;if (scene == null || skeleton == null) {return;}@@ -606,8 +572,8 @@ export class SelectionRenderService implements ISelectionRenderService {return;}- const scene = this.getScene();- const skeleton = this.getSkeleton();+ const scene = this._scene;+ const skeleton = this._skeleton;if (scene == null || skeleton == null) {return;}@@ -752,7 +718,7 @@ export class SelectionRenderService implements ISelectionRenderService {}private _endSelection() {- const scene = this.getScene();+ const scene = this._scene;if (scene == null) {return;}@@ -768,7 +734,7 @@ export class SelectionRenderService implements ISelectionRenderService {}private _addCancelObserver() {- const scene = this.getScene();+ const scene = this._scene;if (scene == null) {return;}diff --git a/packages/ui-plugin-sheets/src/services/selection/selection-shape.ts b/packages/ui-plugin-sheets/src/services/selection/selection-shape.tsindex b287f10863..2c74f23c52 100644--- a/packages/ui-plugin-sheets/src/services/selection/selection-shape.ts+++ b/packages/ui-plugin-sheets/src/services/selection/selection-shape.ts@@ -54,19 +54,13 @@ const SELECTION_TITLE_HIGHLIGHT_ALPHA = 0.3;*/export class SelectionShape {private _leftControl!: Rect;-private _rightControl!: Rect;-private _topControl!: Rect;-private _bottomControl!: Rect;private _backgroundControlTop!: Rect;-private _backgroundControlBottom!: Rect;-private _backgroundControlMiddleLeft!: Rect;-private _backgroundControlMiddleRight!: Rect;private _fillControl!: Rect;@@ -74,35 +68,21 @@ export class SelectionShape {private _selectionShape!: Group;private _rowHeaderBackground!: Rect;-private _rowHeaderBorder!: Rect;-private _rowHeaderGroup!: Group;-private _rowHeaderHighlight!: Rect;-private _columnHeaderBackground!: Rect;-private _columnHeaderBorder!: Rect;-private _columnHeaderGroup!: Group;-private _columnHeaderHighlight!: Rect;private _topLeftWidget!: Rect;-private _topCenterWidget!: Rect;-private _topRightWidget!: Rect;-private _middleLeftWidget!: Rect;-private _middleRightWidget!: Rect;-private _bottomLeftWidget!: Rect;-private _bottomCenterWidget!: Rect;-private _bottomRightWidget!: Rect;private _dashRect!: Rect;@@ -112,25 +92,18 @@ export class SelectionShape {private _selectionStyle: Nullable<ISelectionStyle>;private _rowHeaderWidth: number = 0;-private _columnHeaderHeight: number = 0;private _widgetRects: Rect[] = [];private _dispose$ = new BehaviorSubject<SelectionShape>(this);-readonly dispose$ = this._dispose$.asObservable();readonly selectionMoving$ = new BehaviorSubject<Nullable<IRangeWithCoord>>(null);-readonly selectionMoved$ = new BehaviorSubject<Nullable<IRangeWithCoord>>(null);-readonly selectionScaling$ = new BehaviorSubject<Nullable<IRangeWithCoord>>(null);-readonly selectionScaled$ = new BehaviorSubject<Nullable<IRangeWithCoord>>(null);-readonly selectionFilling$ = new BehaviorSubject<Nullable<IRangeWithCoord>>(null);-readonly selectionFilled$ = new BehaviorSubject<Nullable<IRangeWithCoord>>(null);private _defaultStyle!: ISelectionStyle;@@ -232,21 +205,6 @@ export class SelectionShape {return this._dashRect;}- static fromJson(- scene: Scene,- zIndex: number,- newSelectionData: ISelectionWithCoordAndStyle,- rowHeaderWidth: number,- columnHeaderHeight: number,- isHeaderHighlight: boolean,- themeService: ThemeService- ) {- const { rangeWithCoord, primaryWithCoord, style } = newSelectionData;- const control = new SelectionShape(scene, zIndex, isHeaderHighlight, themeService);- control.update(rangeWithCoord, rowHeaderWidth, columnHeaderHeight, style, primaryWithCoord);- return control;- }-enableHeaderHighlight() {this._isHeaderHighlight = true;}@@ -260,7 +218,7 @@ export class SelectionShape {** inner update*/- _updateControl(style: Nullable<ISelectionStyle>, rowHeaderWidth: number, columnHeaderHeight: number) {+ private _updateControl(style: Nullable<ISelectionStyle>, rowHeaderWidth: number, columnHeaderHeight: number) {const { startX, startY, endX, endY } = this._selectionModel;const defaultStyle = this._defaultStyle;if (style == null) {@@ -432,37 +390,22 @@ export class SelectionShape {this._selectionShape?.dispose();this._rowHeaderBackground?.dispose();-this._rowHeaderBorder?.dispose();-this._rowHeaderGroup?.dispose();-this._rowHeaderBackground?.dispose();-this._columnHeaderBackground?.dispose();-this._columnHeaderBorder?.dispose();-this._columnHeaderGroup?.dispose();this._topLeftWidget?.dispose();-this._topCenterWidget?.dispose();-this._topRightWidget?.dispose();-this._middleLeftWidget?.dispose();-this._middleRightWidget?.dispose();-this._bottomLeftWidget?.dispose();-this._bottomCenterWidget?.dispose();-this._bottomRightWidget?.dispose();-this._dispose$.next(this);-this._dispose$.complete();}diff --git a/packages/ui-plugin-sheets/src/services/sheet-skeleton-manager.service.ts b/packages/ui-plugin-sheets/src/services/sheet-skeleton-manager.service.tsindex f82202d521..000743dc44 100644--- a/packages/ui-plugin-sheets/src/services/sheet-skeleton-manager.service.ts+++ b/packages/ui-plugin-sheets/src/services/sheet-skeleton-manager.service.ts@@ -33,7 +33,6 @@ export class SheetSkeletonManagerService implements IDisposable {private _sheetSkeletonParam: ISheetSkeletonManagerParam[] = [];private readonly _currentSkeleton$ = new BehaviorSubject<Nullable<ISheetSkeletonManagerParam>>(null);-readonly currentSkeleton$ = this._currentSkeleton$.asObservable();/**diff --git a/packages/ui-plugin-sheets/src/views/header-unhide-shape.ts b/packages/ui-plugin-sheets/src/views/header-unhide-shape.tsindex 81c1ab5c07..ea2016ccbc 100644--- a/packages/ui-plugin-sheets/src/views/header-unhide-shape.ts+++ b/packages/ui-plugin-sheets/src/views/header-unhide-shape.ts@@ -18,7 +18,7 @@ export interface IHeaderUnhideShapeProps extends IShapeProps {hasNext: boolean;}-const UNHIDE_ICON_SIZE = 12;+export const UNHIDE_ICON_SIZE = 12;const UNHIDE_ARROW_RATIO = 0.4;export class HeaderUnhideShape<T extends IHeaderUnhideShapeProps = IHeaderUnhideShapeProps> extends Shape<T> {