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
fix(sheet): status bar (#785)
YuHong8bb9e3275057
diff --git a/packages/engine-render/src/viewport.ts b/packages/engine-render/src/viewport.tsindex 2e3917d888..897382c45a 100644--- a/packages/engine-render/src/viewport.ts+++ b/packages/engine-render/src/viewport.ts@@ -379,7 +379,20 @@ export class Viewport {}scrollByBar(pos: IScrollBarPosition, isTrigger = true) {- this._scroll(SCROLL_TYPE.scrollBy, pos, isTrigger, true);+ this._scroll(SCROLL_TYPE.scrollBy, pos, isTrigger);+ const { x, y } = pos;+ this.onScrollByBarObserver.notifyObservers({+ viewport: this,+ scrollX: this.scrollX,+ scrollY: this.scrollY,+ x,+ y,+ actualScrollX: this.actualScrollX,+ actualScrollY: this.actualScrollY,+ limitX: this._scrollBar?.limitX,+ limitY: this._scrollBar?.limitY,+ isTrigger,+ });}/**@@ -868,7 +881,7 @@ export class Viewport {}, 200);}- private _scroll(scrollType: SCROLL_TYPE, pos: IScrollBarPosition, isTrigger = true, isFromBar = false) {+ private _scroll(scrollType: SCROLL_TYPE, pos: IScrollBarPosition, isTrigger = true) {const { x, y } = pos;if (this._scrollBar == null) {@@ -935,21 +948,6 @@ export class Viewport {isTrigger,});- if (isFromBar) {- this.onScrollByBarObserver.notifyObservers({- viewport: this,- scrollX: this.scrollX,- scrollY: this.scrollY,- x,- y,- actualScrollX: scroll.x,- actualScrollY: scroll.y,- limitX: this._scrollBar?.limitX,- limitY: this._scrollBar?.limitY,- isTrigger,- });- }-this._triggerScrollStop(scroll, x, y, isTrigger);return limited;diff --git a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.tsindex d7cee8de42..cfca271039 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts@@ -37,6 +37,7 @@ import { beforeEach, describe, expect, it } from 'vitest';import { AutoFillController } from '../../../controllers/auto-fill.controller';import { AutoFillService, IAutoFillService } from '../../../services/auto-fill/auto-fill.service';+import { EditorBridgeService, IEditorBridgeService } from '../../../services/editor-bridge.service';import { ISelectionRenderService, SelectionRenderService } from '../../../services/selection/selection-render.service';const theme = {@@ -239,6 +240,7 @@ describe('Test auto fill rules in controller', () => {[IAutoFillService, { useClass: AutoFillService }],[IShortcutService, { useClass: DesktopShortcutService }],[IPlatformService, { useClass: DesktopPlatformService }],+ [IEditorBridgeService, { useClass: EditorBridgeService }],[AutoFillController],]);univer = testBed.univer;diff --git a/packages/sheets-ui/src/commands/commands/auto-fill.command.ts b/packages/sheets-ui/src/commands/commands/auto-fill.command.tsindex aa3e976613..ba3335dc2e 100644--- a/packages/sheets-ui/src/commands/commands/auto-fill.command.ts+++ b/packages/sheets-ui/src/commands/commands/auto-fill.command.ts@@ -22,6 +22,7 @@ import {IUniverInstanceService,ObjectMatrix,RANGE_TYPE,+ Rectangle,} from '@univerjs/core';import type {IAddWorksheetMergeMutationParams,@@ -58,7 +59,6 @@ export const AutoFillCommand: ICommand = {const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const undoRedoService = accessor.get(IUndoRedoService);-const {applyRange,selectionRange,@@ -71,6 +71,39 @@ export const AutoFillCommand: ICommand = {return false;}+ const undoSeq: IMutationInfo[] = [];+ const redoSeq: IMutationInfo[] = [];++ // delete cross merge+ let removeMergeResult = true;+ const deleteMergeRanges: IRange[] = [];+ const mergeData = univerInstanceService+ .getUniverSheetInstance(unitId)+ ?.getSheetBySheetId(subUnitId)+ ?.getMergeData();+ if (mergeData) {+ mergeData.forEach((merge) => {+ if (Rectangle.intersects(merge, applyRange)) {+ deleteMergeRanges.push(merge);+ }+ });+ }+ const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {+ unitId,+ subUnitId,+ ranges: deleteMergeRanges,+ };+ const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(+ accessor,+ removeMergeMutationParams+ );+ removeMergeResult = commandService.syncExecuteCommand(+ RemoveWorksheetMergeMutation.id,+ removeMergeMutationParams+ );+ undoSeq.push({ id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams });+ redoSeq.push({ id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams });+// set range valueconst cellValue = new ObjectMatrix<ICellData>();const { startRow, startColumn, endRow, endColumn } = applyRange;@@ -97,6 +130,9 @@ export const AutoFillCommand: ICommand = {setRangeValuesMutationParams);+ undoSeq.push({ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams });+ redoSeq.push({ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams });+// set selectionconst selectionResult = commandService.syncExecuteCommand(SetSelectionsOperation.id, {selections: [@@ -116,28 +152,15 @@ export const AutoFillCommand: ICommand = {subUnitId,});- const undoSeq: IMutationInfo[] = [{ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams }];- const redoSeq: IMutationInfo[] = [{ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams }];+ undoSeq.push({ id: SetRangeValuesMutation.id, params: undoSetRangeValuesMutationParams });+ redoSeq.push({ id: SetRangeValuesMutation.id, params: setRangeValuesMutationParams });- let removeMergeResult = true;let addMergeResult = true;// add worksheet mergeif (applyMergeRanges?.length) {const ranges = getAddMergeMutationRangeByType(applyMergeRanges);- const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {- unitId,- subUnitId,- ranges,- };- const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(- accessor,- removeMergeMutationParams- );- removeMergeResult = commandService.syncExecuteCommand(- RemoveWorksheetMergeMutation.id,- removeMergeMutationParams- );+const addMergeMutationParams: IAddWorksheetMergeMutationParams = {unitId,subUnitId,@@ -149,9 +172,7 @@ export const AutoFillCommand: ICommand = {);addMergeResult = commandService.syncExecuteCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);- undoSeq.push({ id: AddWorksheetMergeMutation.id, params: undoRemoveMergeMutationParams });undoSeq.push({ id: RemoveWorksheetMergeMutation.id, params: undoRemoveMutationParams });- redoSeq.push({ id: RemoveWorksheetMergeMutation.id, params: removeMergeMutationParams });redoSeq.push({ id: AddWorksheetMergeMutation.id, params: addMergeMutationParams });}diff --git a/packages/sheets-ui/src/controllers/auto-fill.controller.ts b/packages/sheets-ui/src/controllers/auto-fill.controller.tsindex 2b57e0d5ff..72a2947efd 100644--- a/packages/sheets-ui/src/controllers/auto-fill.controller.ts+++ b/packages/sheets-ui/src/controllers/auto-fill.controller.ts@@ -26,7 +26,7 @@ import {toDisposable,Tools,} from '@univerjs/core';-import { getCellInfoInMergeData } from '@univerjs/engine-render';+import { DeviceInputEventType, getCellInfoInMergeData } from '@univerjs/engine-render';import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '@univerjs/sheets';import { Inject } from '@wendellhu/redi';@@ -36,6 +36,7 @@ import { otherRule } from '../services/auto-fill/rules';import { fillCopy, fillCopyStyles, getDataIndex, getLenS } from '../services/auto-fill/tools';import type { APPLY_FUNCTIONS, ICopyDataInType, ICopyDataPiece, IRuleConfirmedData } from '../services/auto-fill/type';import { APPLY_TYPE, DATA_TYPE } from '../services/auto-fill/type';+import { IEditorBridgeService } from '../services/editor-bridge.service';import { ISelectionRenderService } from '../services/selection/selection-render.service';@OnLifecycle(LifecycleStages.Steady, AutoFillController)@@ -51,6 +52,7 @@ export class AutoFillController extends Disposable {@ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService,@ICommandService private readonly _commandService: ICommandService,@IAutoFillService private readonly _autoFillService: IAutoFillService,+ @IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService) {super();@@ -216,6 +218,20 @@ export class AutoFillController extends Disposable {})));++ disposableCollection.add(+ toDisposable(+ controlSelection.fillControl.onPointerDownObserver.add(() => {+ const visibleState = this._editorBridgeService.isVisible();+ if (visibleState.visible) {+ this._editorBridgeService.changeVisible({+ visible: false,+ eventType: DeviceInputEventType.PointerDown,+ });+ }+ })+ )+ );});}))diff --git a/packages/sheets-ui/src/controllers/mark-selection.controller.ts b/packages/sheets-ui/src/controllers/mark-selection.controller.tsnew file mode 100644index 0000000000..07d55b97cb--- /dev/null+++ b/packages/sheets-ui/src/controllers/mark-selection.controller.ts@@ -0,0 +1,64 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICommandInfo } from '@univerjs/core';+import { Disposable, ICommandService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';+import { SetRangeValuesMutation } from '@univerjs/sheets';+import { Inject } from '@wendellhu/redi';++import { SetCellEditVisibleOperation } from '../commands/operations/cell-edit.operation';+import { IMarkSelectionService } from '../services/mark-selection/mark-selection.service';+import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';++@OnLifecycle(LifecycleStages.Steady, MarkSelectionController)+export class MarkSelectionController extends Disposable {+ constructor(+ @Inject(IMarkSelectionService) private _markSelectionService: IMarkSelectionService,+ @ICommandService private _commandService: ICommandService,+ @Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService+ ) {+ super();+ this._initListeners();+ }++ private _initListeners() {+ this._addRemoveListener();+ this._addRefreshListener();+ }++ private _addRemoveListener() {+ const removeCommands = [SetCellEditVisibleOperation.id, SetRangeValuesMutation.id];+ this.disposeWithMe(+ this._commandService.onCommandExecuted((command: ICommandInfo) => {+ if (removeCommands.includes(command.id)) {+ this._markSelectionService.removeAllShapes();+ }+ })+ );+ }++ private _addRefreshListener() {+ this.disposeWithMe(+ toDisposable(+ this._sheetSkeletonManagerService.currentSkeleton$.subscribe((skeleton) => {+ if (skeleton) {+ this._markSelectionService.refreshShapes();+ }+ })+ )+ );+ }+}diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.tsindex c62ca273a1..18a03de79f 100644--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts@@ -38,6 +38,7 @@ import { IStatusBarService } from '../services/status-bar.service';@OnLifecycle(LifecycleStages.Ready, StatusBarController)export class StatusBarController extends Disposable {+ private _calculateTimeout: number | NodeJS.Timeout = -1;constructor(@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,@@ -59,7 +60,10 @@ export class StatusBarController extends Disposable {toDisposable(this._selectionManagerService.selectionMoving$.subscribe((selections) => {if (selections) {- this._calculateSelection(selections.map((selection) => selection.range));+ clearTimeout(this._calculateTimeout);+ this._calculateTimeout = setTimeout(() => {+ this._calculateSelection(selections.map((selection) => selection.range));+ }, 100);}}))diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.tsindex 65ef2a43cb..e91e2c324b 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts@@ -513,6 +513,8 @@ export class testMarkSelectionService {removeShape(id: string): void {}removeAllShapes(): void {}++ refreshShapes(): void {}}export function clipboardTestBed(workbookConfig?: IWorkbookData, dependencies?: Dependency[]) {diff --git a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.tsindex 3ee5f738ee..3c88664ea6 100644--- a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts+++ b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts@@ -14,14 +14,12 @@* limitations under the License.*/-import type { ICommandInfo } from '@univerjs/core';import { Disposable, ICommandService, IUniverInstanceService, ThemeService, Tools } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';import type { ISelectionWithStyle } from '@univerjs/sheets';-import { SelectionManagerService, SetRangeValuesMutation, SetWorksheetActiveOperation } from '@univerjs/sheets';+import { SelectionManagerService } from '@univerjs/sheets';import { createIdentifier, Inject } from '@wendellhu/redi';-import { SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';import { ISelectionRenderService } from '../selection/selection-render.service';import { SelectionShape } from '../selection/selection-shape';import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';@@ -30,6 +28,7 @@ export interface IMarkSelectionService {addShape(selection: ISelectionWithStyle, zIndex?: number): string | null;removeShape(id: string): void;removeAllShapes(): void;+ refreshShapes(): void;}interface IMarkSelectionInfo {@@ -56,8 +55,6 @@ export class MarkSelectionService extends Disposable implements IMarkSelectionSe@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService) {super();- this._addRemoveListener();- this._addRefreshListener();}addShape(selection: ISelectionWithStyle, zIndex: number = DEFAULT_Z_INDEX): string | null {@@ -76,27 +73,25 @@ export class MarkSelectionService extends Disposable implements IMarkSelectionSe}refreshShapes() {- const currentunitId = this._currentService.getCurrentUniverSheetInstance().getUnitId();- const currentsubUnitId = this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();- setTimeout(() => {- this._shapeMap.forEach((shape) => {- const { unitId, subUnitId, selection, control: oldControl, zIndex } = shape;- if (unitId !== currentunitId || subUnitId !== currentsubUnitId) {- oldControl && oldControl.dispose();- return;- }- const { style } = selection;- const { scene } = this._renderManagerService.getRenderById(unitId) || {};- const { rangeWithCoord, primaryWithCoord } =- this._selectionRenderService.convertSelectionRangeToData(selection);- const skeleton = this._sheetSkeletonManagerService.getCurrent()?.skeleton;- if (!scene || !skeleton) return;- const { rowHeaderWidth, columnHeaderHeight } = skeleton;- const control = new SelectionShape(scene, zIndex, false, this._themeService);- control.update(rangeWithCoord, rowHeaderWidth, columnHeaderHeight, style, primaryWithCoord);- shape.control = control;- });- }, 0);+ const currentUnitId = this._currentService.getCurrentUniverSheetInstance().getUnitId();+ const currentSubUnitId = this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();+ this._shapeMap.forEach((shape) => {+ const { unitId, subUnitId, selection, control: oldControl, zIndex } = shape;+ if (unitId !== currentUnitId || subUnitId !== currentSubUnitId) {+ oldControl && oldControl.dispose();+ return;+ }+ const { style } = selection;+ const { scene } = this._renderManagerService.getRenderById(unitId) || {};+ const { rangeWithCoord, primaryWithCoord } =+ this._selectionRenderService.convertSelectionRangeToData(selection);+ const skeleton = this._sheetSkeletonManagerService.getCurrent()?.skeleton;+ if (!scene || !skeleton) return;+ const { rowHeaderWidth, columnHeaderHeight } = skeleton;+ const control = new SelectionShape(scene, zIndex, false, this._themeService);+ control.update(rangeWithCoord, rowHeaderWidth, columnHeaderHeight, style, primaryWithCoord);+ shape.control = control;+ });}removeShape(id: string): void {@@ -114,26 +109,4 @@ export class MarkSelectionService extends Disposable implements IMarkSelectionSe}this._shapeMap.clear();}-- private _addRemoveListener() {- const removeCommands = [SetCellEditVisibleOperation.id, SetRangeValuesMutation.id];- this.disposeWithMe(- this._commandService.onCommandExecuted((command: ICommandInfo) => {- if (removeCommands.includes(command.id)) {- this.removeAllShapes();- }- })- );- }-- private _addRefreshListener() {- const refreshCommands = [SetWorksheetActiveOperation.id];- this.disposeWithMe(- this._commandService.onCommandExecuted((command: ICommandInfo) => {- if (refreshCommands.includes(command.id)) {- this.refreshShapes();- }- })- );- }}diff --git a/packages/sheets-ui/src/services/status-bar.service.ts b/packages/sheets-ui/src/services/status-bar.service.tsindex af556fb081..03937b536e 100644--- a/packages/sheets-ui/src/services/status-bar.service.ts+++ b/packages/sheets-ui/src/services/status-bar.service.ts@@ -43,39 +43,40 @@ export interface IStatusBarFunction {export class StatusBarService implements IStatusBarService, IDisposable {private readonly _functions: IStatusBarFunction[] = [{- func: FUNCTION_NAMES_MATH.SUM,+ func: FUNCTION_NAMES_STATISTICAL.MAX,filter: (status: IStatusBarServiceStatus) =>(status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&(status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,},{- func: FUNCTION_NAMES_STATISTICAL.MAX,+ func: FUNCTION_NAMES_STATISTICAL.MIN,filter: (status: IStatusBarServiceStatus) =>(status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&(status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,},{- func: FUNCTION_NAMES_STATISTICAL.MIN,+ func: FUNCTION_NAMES_MATH.SUM,filter: (status: IStatusBarServiceStatus) =>(status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&(status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,},{- func: FUNCTION_NAMES_STATISTICAL.AVERAGE,+ func: FUNCTION_NAMES_STATISTICAL.COUNTA,filter: (status: IStatusBarServiceStatus) =>- (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&- (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1,},{func: FUNCTION_NAMES_STATISTICAL.COUNT,filter: (status: IStatusBarServiceStatus) =>- (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 1 &&+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&(status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,},+{- func: FUNCTION_NAMES_STATISTICAL.COUNTA,+ func: FUNCTION_NAMES_STATISTICAL.AVERAGE,filter: (status: IStatusBarServiceStatus) =>- (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1,+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNTA)?.value ?? 0) > 1 &&+ (status.find((item) => item.func === FUNCTION_NAMES_STATISTICAL.COUNT)?.value ?? 0) > 0,},];private readonly _state$ = new BehaviorSubject<Nullable<IStatusBarServiceStatus>>(null);diff --git a/packages/sheets-ui/src/sheets-ui-plugin.ts b/packages/sheets-ui/src/sheets-ui-plugin.tsindex a1cf3272d6..bd5548aa2d 100644--- a/packages/sheets-ui/src/sheets-ui-plugin.ts+++ b/packages/sheets-ui/src/sheets-ui-plugin.ts@@ -37,6 +37,7 @@ import { HeaderMenuController } from './controllers/header-menu.controller';import { HeaderMoveController } from './controllers/header-move.controller';import { HeaderResizeController } from './controllers/header-resize.controller';import { HeaderUnhideController } from './controllers/header-unhide.controller';+import { MarkSelectionController } from './controllers/mark-selection.controller';import { MoveRangeController } from './controllers/move-range.controller';import { SheetNavigationController } from './controllers/navigation/navigation.controller';import { ScrollController } from './controllers/scroll.controller';@@ -130,6 +131,7 @@ export class UniverSheetsUIPlugin extends Plugin {[AutoFillController],[StatusBarController],[EditingController],+ [MarkSelectionController],] as Dependency[]).forEach((d) => injector.add(d));}diff --git a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx b/packages/sheets-ui/src/views/status-bar/StatusBar.tsxindex a1b3cc12b1..7e2a120d6b 100644--- a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx+++ b/packages/sheets-ui/src/views/status-bar/StatusBar.tsx@@ -14,47 +14,32 @@* limitations under the License.*/-import { LocaleService } from '@univerjs/core';-import { Checkbox, Dropdown } from '@univerjs/design';-import { MoreSingle } from '@univerjs/icons';import { useDependency } from '@wendellhu/redi/react-bindings';import clsx from 'clsx';import React, { useEffect, useState } from 'react';import { IStatusBarService } from '../../services/status-bar.service';import type { IStatisticItem } from './CopyableStatisticItem';-import { CopyableStatisticItem, formatNumber, functionDisplayNames } from './CopyableStatisticItem';+import { CopyableStatisticItem } from './CopyableStatisticItem';import styles from './index.module.less';const SINGLE_MODE_WIDTH = 800;+const ROW_COUNT_THRESHOLD = 3;export const StatusBar = () => {const [isSingle, setIsSingle] = useState(window.innerWidth < SINGLE_MODE_WIDTH);const [show, setShow] = useState(true);- const localeService = useDependency(LocaleService);const statusBarService = useDependency(IStatusBarService);const items = statusBarService.getFunctions().map((item, index) => ({name: item.func,value: 0,- show: isSingle ? index < 1 : index < 3,+ show: true,disable: false,}));const [statistics, setStatistics] = useState<IStatisticItem[]>(items);- const enabledList = statistics.filter((item) => !item.disable);- const showList = statistics.filter((item) => item.show && !item.disable);-- const onChange = (item: IStatisticItem) => {- const newStatistics = statistics.map((stat) => {- if (stat.name === item.name) {- stat.show = !stat.show;- } else if (isSingle) {- stat.show = false;- }- return stat;- });- setStatistics(newStatistics);- };+ const firstItem = statistics.find((item) => item.show && !item.disable);+ const showList = isSingle && firstItem ? [firstItem] : statistics.filter((item) => item.show && !item.disable);useEffect(() => {const subscription = statusBarService.state$.subscribe((item) => {@@ -80,25 +65,12 @@ export const StatusBar = () => {};}, [statusBarService]);- const handleResize = () => {+ const handleResize = debounce(() => {const newSingleState = window.innerWidth < SINGLE_MODE_WIDTH;if (isSingle !== newSingleState) {- if (newSingleState) {- // keep the items hide except the first show item- const firstIndex = statistics.findIndex((item) => item.show);- const newStatistics = statistics.map((stat, index) => {- if (index === firstIndex) {- stat.show = true;- } else {- stat.show = false;- }- return stat;- });- setStatistics(newStatistics);- }setIsSingle(newSingleState);}- };+ }, 100);useEffect(() => {window.addEventListener('resize', handleResize);@@ -106,7 +78,36 @@ export const StatusBar = () => {return () => {window.removeEventListener('resize', handleResize);};- }, []);+ }, [isSingle]);++ let renderContent = null;+ if (showList.length > ROW_COUNT_THRESHOLD) {+ const doubleLineList: IStatisticItem[][] = [];+ showList.forEach((_, index) => {+ if (index % 2 === 0) {+ doubleLineList.push(showList.slice(index, index + 2));+ }+ });+ renderContent = (+ <>+ {' '}+ {doubleLineList!.map((item: IStatisticItem[], index: number) => (+ <div key={`stat-col-${index}`} className={styles.statisticListColumn}>+ {item?.[0] && <CopyableStatisticItem key={item?.[0].name} {...item?.[0]} />}+ {item?.[1] && <CopyableStatisticItem key={item?.[1].name} {...item?.[1]} />}+ </div>+ ))}{' '}+ </>+ );+ } else {+ renderContent = (+ <>+ {showList.map((item) => (+ <CopyableStatisticItem key={item.name} {...item} />+ ))}+ </>+ );+ }return (show && (@@ -115,53 +116,27 @@ export const StatusBar = () => {[styles.singleMode]: isSingle,})}>- <div- className={clsx(styles.statisticList, {- [styles.statisticListTwoRow]: showList.length > 3,- })}- >- {showList.length > 3 ? (- <>- <div className={styles.statisticListRow}>- {showList.slice(0, 3).map((item) => (- <CopyableStatisticItem key={item.name} {...item} />- ))}- </div>- <div className={styles.statisticListRow}>- {showList.slice(3).map((item) => (- <CopyableStatisticItem key={item.name} {...item} />- ))}- </div>- </>- ) : (- showList.map((item) => <CopyableStatisticItem key={item.name} {...item} />)- )}- </div>- <Dropdown- placement="topRight"- overlay={- <div className={styles.statisticPicker}>- {enabledList?.map((item) => (- <a key={item.name} className={styles.statisticPickerItem}>- <Checkbox- value={item.name}- checked={item.show}- onChange={() => onChange && onChange(item)}- />- <span>{`${localeService.t(- functionDisplayNames?.[item.name as string] || (item.name as string)- )}: ${formatNumber(item.value)}`}</span>- </a>- ))}- </div>- }- >- <div className={styles.statisticMore}>- <MoreSingle />- </div>- </Dropdown>+ <div className={clsx(styles.statisticList)}>{renderContent}</div><div className={styles.statusBarDiv} /></div>));};++type DebounceFn<T extends (...args: any[]) => any> = (this: ThisParameterType<T>, ...args: Parameters<T>) => void;++function debounce<T extends (...args: any[]) => any>(func: T, wait: number): DebounceFn<T> {+ let timeout: NodeJS.Timeout | null;++ return function (this: ThisParameterType<T>, ...args: Parameters<T>) {+ const context = this;++ const later = function () {+ timeout = null;+ func.apply(context, args);+ };++ clearTimeout(timeout as NodeJS.Timeout);+ timeout = setTimeout(later, wait);+ };+}diff --git a/packages/sheets-ui/src/views/status-bar/index.module.less b/packages/sheets-ui/src/views/status-bar/index.module.lessindex af4efb96ce..599ccbff47 100644--- a/packages/sheets-ui/src/views/status-bar/index.module.less+++ b/packages/sheets-ui/src/views/status-bar/index.module.less@@ -23,23 +23,20 @@display: flex;}- &-list-two-row {+ &-list-column {flex-direction: column;}- &-list-two-row &-list-row {- display: flex;- flex-direction: row;- }-- &-list-two-row &-item{- font-size: 11px;+ &-list-column &-item{+ font-size: 12px;line-height: 140%;+ color: rgb(var(--grey-500));}&-item {cursor: default;+ overflow: hidden;display: flex;justify-content: start;@@ -50,8 +47,10 @@font-weight: 400;font-style: normal;line-height: 20px; /* 181.818% */- color: rgb(var(--grey-1000));+ color: rgb(var(--grey-900));text-align: center;+ text-overflow: ellipsis;+ white-space: nowrap;}&-picker {diff --git a/packages/sheets/src/services/selection-manager.service.ts b/packages/sheets/src/services/selection-manager.service.tsindex fdbe28d80a..216dfbf7ef 100644--- a/packages/sheets/src/services/selection-manager.service.ts+++ b/packages/sheets/src/services/selection-manager.service.ts@@ -283,7 +283,7 @@ export class SelectionManagerService implements IDisposable {createCopyPasteSelection(): ISelectionStyle {return {- strokeWidth: 2,+ strokeWidth: 1.5,stroke: this._themeService.getCurrentTheme().primaryColor,fill: 'rgba(178, 178, 178, 0.10)',widgets: {},diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 884be9cafe..2dbacda448 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2551,7 +2551,7 @@ packages:'@babel/core': 7.23.5clone-deep: 4.0.1find-cache-dir: 2.1.0- make-dir: 2.1.0+ make-dir: registry.npmmirror.com/[email protected]pirates: 4.0.6source-map-support: 0.5.21dev: true@@ -3689,7 +3689,7 @@ packages:'@rushstack/rig-package': 0.5.1'@rushstack/ts-command-line': 4.17.1colors: 1.2.5- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]resolve: 1.22.8semver: 7.5.4source-map: 0.6.1@@ -4548,7 +4548,7 @@ packages:resolution: {integrity: sha512-k4AtZfazmD/nL3JAtLGAB7raPhkhUo0jWnaZWrahd9h1Fm13mBU/RW+JzTRhCw3Mp2HPERD7NI5Qcd2fUP6WDA==}dependencies:- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]ts-dedent: 2.2.0transitivePeerDependencies:- '@types/react'@@ -4693,10 +4693,10 @@ packages:'@storybook/preview-api': 7.6.4'@storybook/theming': 7.6.4([email protected])([email protected])'@storybook/types': 7.6.4- '@types/lodash': 4.14.202+ '@types/lodash': registry.npmmirror.com/@types/[email protected]color-convert: 2.0.1dequal: 2.0.3- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]markdown-to-jsx: 7.3.2([email protected])memoizerific: 1.11.3polished: 4.2.2@@ -4859,7 +4859,7 @@ packages:cross-spawn: 7.0.3globby: 11.1.0jscodeshift: 0.15.1(@babel/[email protected])- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]prettier: 2.8.8recast: 0.23.4transitivePeerDependencies:@@ -4964,7 +4964,7 @@ packages:fs-extra: 11.1.1globby: 11.1.0ip: 2.0.0- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]open: 8.4.2pretty-hrtime: 1.0.3prompts: 2.4.2@@ -5028,7 +5028,7 @@ packages:'@types/doctrine': 0.0.3assert: 2.1.0doctrine: 3.0.0- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]transitivePeerDependencies:- encoding- supports-color@@ -5050,7 +5050,7 @@ packages:'@storybook/theming': 7.6.4([email protected])([email protected])'@storybook/types': 7.6.4dequal: 2.0.3- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]memoizerific: 1.11.3semver: 7.5.4store2: 2.14.2@@ -5088,7 +5088,7 @@ packages:'@storybook/types': 7.6.4'@types/qs': 6.9.10dequal: 2.0.3- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]memoizerific: 1.11.3qs: 6.11.2synchronous-promise: 2.0.17@@ -5163,7 +5163,7 @@ packages:acorn-walk: 7.2.0escodegen: 2.1.0html-tags: 3.3.1- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]prop-types: 15.8.1react: 18.2.0react-dom: 18.2.0([email protected])@@ -5428,10 +5428,6 @@ packages:resolution: {integrity: sha512-PecSzorDGdabF57OBeQO/xFbAkYWo88g4Xvnsx7LRwqLC17I7OoKtA3bQB9uXkY6UkMWCOsA8HSVpaoitscdXw==}dev: true- /@types/[email protected]:- resolution: {integrity: sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==}- dev: true-/@types/[email protected]:resolution: {integrity: sha512-Rllzc5KHk0Al5/WANwgSPl1/CwjqCy+AZrGd78zuK+jO9aDM6ffblZ+zIjgPNAaEBmlO0RYDvLNh7wD0zKVgEg==}dev: true@@ -8157,7 +8153,7 @@ packages:engines: {node: '>=6'}dependencies:commondir: 1.0.1- make-dir: 2.1.0+ make-dir: registry.npmmirror.com/[email protected]pkg-dir: 3.0.0dev: true@@ -8435,7 +8431,7 @@ packages:hasBin: truedependencies:dargs: 7.0.0- lodash: 4.17.21+ lodash: registry.npmmirror.com/[email protected]meow: 8.1.2split2: 3.2.2through2: 4.0.2@@ -9598,7 +9594,7 @@ packages:resolution: {integrity: sha512-OfCBkGEw4nN6JLtgRidPX6QxjBQGQf72q3si2uvqyFEMbycSFFHwAZeXx6cJgFM9wmLrf9zBwCP3Ivqa+LLZPw==}engines: {node: '>=6'}dependencies:- graceful-fs: 4.2.11+ graceful-fs: registry.npmmirror.com/[email protected]js-yaml: 3.14.1pify: 4.0.1strip-bom: 3.0.0@@ -9703,6 +9699,7 @@ packages:resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}+ dev: falseresolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==}@@ -9796,10 +9793,12 @@ packages:resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==}engines: {node: '>=6'}+ requiresBuild: truedependencies:pify: 4.0.1semver: 5.7.2dev: true+ optional: trueresolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==}@@ -9972,7 +9971,9 @@ packages:resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==}engines: {node: '>=4'}hasBin: true+ requiresBuild: truedev: true+ optional: trueresolution: {integrity: sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==}@@ -11824,7 +11825,7 @@ packages:etag: 1.8.1fresh: 0.5.2http-errors: 2.0.0- mime: 1.6.0+ mime: registry.npmmirror.com/[email protected]ms: 2.1.3on-finished: 2.4.1range-parser: 1.2.1@@ -11987,7 +11988,7 @@ packages:resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}dependencies:buffer-from: 1.1.2- source-map: 0.6.1+ source-map: registry.npmmirror.com/[email protected]dev: true@@ -13334,7 +13335,7 @@ packages:engines: {node: '>=10.13.0'}dependencies:glob-to-regexp: 0.4.1- graceful-fs: 4.2.11+ graceful-fs: registry.npmmirror.com/[email protected]dev: true@@ -13511,7 +13512,7 @@ packages:resolution: {integrity: sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==}dependencies:- graceful-fs: 4.2.11+ graceful-fs: registry.npmmirror.com/[email protected]imurmurhash: 0.1.4signal-exit: 3.0.7dev: true@@ -13666,3 +13667,46 @@ packages:optionalDependencies:commander: 9.5.0dev: true++ registry.npmmirror.com/@types/[email protected]:+ resolution: {integrity: sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==, registry: https://registry.npmjs.org/, tarball: https://registry.npmmirror.com/@types/lodash/-/lodash-4.14.202.tgz}+ name: '@types/lodash'+ version: 4.14.202+ dev: true++ registry.npmmirror.com/[email protected]:+ resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==, registry: https://registry.npmjs.org/, tarball: https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.11.tgz}+ name: graceful-fs+ version: 4.2.11+ dev: true++ registry.npmmirror.com/[email protected]:+ resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==, registry: https://registry.npmjs.org/, tarball: https://registry.npmmirror.com/lodash/-/lodash-4.17.21.tgz}+ name: lodash+ version: 4.17.21+ dev: true++ registry.npmmirror.com/[email protected]:+ resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==, registry: https://registry.npmjs.org/, tarball: https://registry.npmmirror.com/make-dir/-/make-dir-2.1.0.tgz}+ name: make-dir+ version: 2.1.0+ engines: {node: '>=6'}+ dependencies:+ pify: 4.0.1+ semver: 5.7.2+ dev: true++ registry.npmmirror.com/[email protected]:+ resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==, registry: https://registry.npmjs.org/, tarball: https://registry.npmmirror.com/mime/-/mime-1.6.0.tgz}+ name: mime+ version: 1.6.0+ engines: {node: '>=4'}+ hasBin: true+ dev: true++ registry.npmmirror.com/[email protected]:+ resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==, registry: https://registry.npmjs.org/, tarball: https://registry.npmmirror.com/source-map/-/source-map-0.6.1.tgz}+ name: source-map+ version: 0.6.1+ engines: {node: '>=0.10.0'}+ dev: true