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: move getHiddenSheets-method to workbook (#264)
YuHong0260a7025503
diff --git a/packages/base-ui/src/Components/Tabs/Tabs.tsx b/packages/base-ui/src/Components/Tabs/Tabs.tsxindex e95607234f..10594bfe90 100644--- a/packages/base-ui/src/Components/Tabs/Tabs.tsx+++ b/packages/base-ui/src/Components/Tabs/Tabs.tsx@@ -1,4 +1,4 @@-import React, { createRef, ReactNode, useEffect, useState } from 'react';+import React, { createRef, ReactNode, useEffect, useImperativeHandle, useState } from 'react';import { joinClassNames, randomId } from '../../Utils';import styles from './index.module.less';@@ -91,11 +91,15 @@ interface ITabInfo {max: number;}+export interface ITabRef {+ scrollContent: (offset: number) => void;+}+/*** Tabs Component*/export const Tabs = React.memo(- (props: IBaseTabsProps) => {+ React.forwardRef<ITabRef, IBaseTabsProps>((props: IBaseTabsProps, ref) => {const { type = 'line', className = '', draggable = false } = props;const [active, setActive] = useState<string>(props.activeKey ?? ''); // Initialize active with the provided activeKey@@ -204,6 +208,16 @@ export const Tabs = React.memo(}};+ const scrollContent = (offset: number) => {+ if (parent.current) {+ parent.current.scrollLeft += offset;+ }+ };++ useImperativeHandle(ref, () => ({+ scrollContent,+ }));+// 动画函数const scrollToAnimation = (current: HTMLDivElement, direction: 'left' | 'right') => () => {let scrollLeft;@@ -393,7 +407,7 @@ export const Tabs = React.memo(</div></div>);- },+ }),(prev, next) =>prev.children.length === next.children.length &&prev.activeKey === next.activeKey &&diff --git a/packages/base-ui/src/Components/Tabs/index.module.less b/packages/base-ui/src/Components/Tabs/index.module.lessindex 2c7fde3869..94ecef6fbb 100644--- a/packages/base-ui/src/Components/Tabs/index.module.less+++ b/packages/base-ui/src/Components/Tabs/index.module.less@@ -25,6 +25,8 @@overflow-x: auto;position: relative;white-space: nowrap;+ scroll-behavior: smooth;+ transition: scroll-behavior 0.3s ease-in-out;}}}diff --git a/packages/core/src/Sheets/Domain/Workbook.ts b/packages/core/src/Sheets/Domain/Workbook.tsindex a4f5cbc5af..f2218b194d 100644--- a/packages/core/src/Sheets/Domain/Workbook.ts+++ b/packages/core/src/Sheets/Domain/Workbook.ts@@ -184,6 +184,12 @@ export class Workbook {return this._worksheets.get(sheetId);}+ getHiddenWorksheets(): string[] {+ return this.getSheets()+ .filter((s) => s.getConfig().hidden === BooleanNumber.TRUE)+ .map((s) => s.getConfig().id);+ }+// getPluginMeta<T>(name: string): T {// return this._config.pluginMeta[name];// }diff --git a/packages/core/src/services/current.service.ts b/packages/core/src/services/current.service.tsindex 12006c45dc..d5cccca9a3 100644--- a/packages/core/src/services/current.service.ts+++ b/packages/core/src/services/current.service.ts@@ -6,7 +6,6 @@ import { Nullable } from '../Shared';import { Disposable } from '../Shared/lifecycle';import { Workbook } from '../Sheets/Domain/Workbook';import { SlideModel } from '../Slides/Domain/SlideModel';-import { BooleanNumber } from '../Types/Enum';import { IDocumentData } from '../Types/Interfaces';import { FOCUSING_DOC, FOCUSING_SHEET, FOCUSING_SLIDE } from './context/context';import { IContextService } from './context/context.service';@@ -15,11 +14,6 @@ export interface IUniverHandler {createUniverDoc(data: Partial<IDocumentData>): DocumentModel;}-export interface IWorksheetDiscriptor {- id: string;- name: string;-}-/*** ICurrentUniverService holds all the current univer instances. And it also manages* the focused univer instance.@@ -60,7 +54,6 @@ export interface ICurrentUniverService {getFocusedUniverInstance(): Workbook | DocumentModel | SlideModel | null;focusUniverInstance(id: string | null): void;- getCurrentUniverHiddenWorksheets(): IWorksheetDiscriptor[];}export const ICurrentUniverService = createIdentifier<ICurrentUniverService>('univer.current');@@ -203,14 +196,4 @@ export class CurrentUniverService extends Disposable implements ICurrentUniverSegetFocusedUniverInstance(): Workbook | DocumentModel | SlideModel | null {return this._focused;}-- getCurrentUniverHiddenWorksheets(): IWorksheetDiscriptor[] {- return this.getCurrentUniverSheetInstance()- .getSheets()- .filter((s) => s.getConfig().hidden === BooleanNumber.TRUE)- .map((s) => ({- id: s.getConfig().name,- name: s.getConfig().id,- }));- }}diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsxindex f0866022c0..4dc8584dc7 100644--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx@@ -19,6 +19,7 @@ import {Icon,IDisplayMenuItem,IMenuItem,+ ITabRef,Menu,TabPane,Tabs,@@ -58,6 +59,8 @@ type SheetState = {activeKey: string;};+const SCROLL_WIDTH = 100;+export class SheetBar extends Component<BaseSheetBarProps, SheetState> {static override contextType = AppContext;@@ -68,8 +71,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {sheetContainerRef = createRef<HTMLDivElement>();sheetContentRef = createRef();-- sheetBarContentRef = createRef();+ sheetBarContentRef = createRef<ITabRef>();// 先生成移动对象的副本,移动对象固定定位,达到边界的时候将副本移位time = 0;@@ -331,6 +333,17 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {commandService.executeCommand(InsertSheetCommand.id, {});}+ private handleScrollLeft = () => {+ if (this.sheetBarContentRef.current) {+ this.sheetBarContentRef.current.scrollContent(-SCROLL_WIDTH);+ }+ };+ private handleScrollRight = () => {+ if (this.sheetBarContentRef.current) {+ this.sheetBarContentRef.current.scrollContent(SCROLL_WIDTH);+ }+ };+override render() {const { sheetList, menuList, sheetUl, showMenu, showManageMenu, menuStyle, activeKey } = this.state;@@ -358,7 +371,13 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {</div>{/* user s button */}- <Tabs draggable className={styles.slideTabBar} activeKey={activeKey} reRenderString={reRenderString}>+ <Tabs+ draggable+ className={styles.slideTabBar}+ activeKey={activeKey}+ reRenderString={reRenderString}+ ref={this.sheetBarContentRef}+ >{sheetList.map((item) => (<TabPanekey={item.sheetId}@@ -429,10 +448,10 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {{/* prev next scroll button */}<div className={`${styles.sheetBarOptions} ${styles.sheetBarScrollButton}`}>- <Button className={styles.sheetBarOptionsButton}>+ <Button className={styles.sheetBarOptionsButton} onClick={this.handleScrollLeft.bind(this)}><Icon.NextIcon rotate={90} style={{ padding: '5px' }} /></Button>- <Button className={styles.sheetBarOptionsButton}>+ <Button className={styles.sheetBarOptionsButton} onClick={this.handleScrollRight.bind(this)}><Icon.NextIcon rotate={-90} style={{ padding: '5px' }} /></Button></div>diff --git a/packages/ui-plugin-sheets/src/controller/menu/menu.ts b/packages/ui-plugin-sheets/src/controller/menu/menu.tsindex 34667547a4..7764970aaf 100644--- a/packages/ui-plugin-sheets/src/controller/menu/menu.ts+++ b/packages/ui-plugin-sheets/src/controller/menu/menu.ts@@ -1261,9 +1261,10 @@ export function HideSheetMenuItemFactory(): IMenuButtonItem {export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<any> {const currentUniverService = accessor.get(ICurrentUniverService);const commandService = accessor.get(ICommandService);- const hiddenList = currentUniverService.getCurrentUniverHiddenWorksheets().map((s) => ({- label: s.name,- value: s.id,+ const workbook = currentUniverService.getCurrentUniverSheetInstance();+ const hiddenList = workbook.getHiddenWorksheets().map((s) => ({+ label: workbook.getSheetBySheetId(s)?.getName() || '',+ value: s,}));return {@@ -1277,10 +1278,7 @@ export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItif (c.id !== SetWorksheetHideCommand.id && c.id !== SetWorksheetShowCommand.id) {return;}- const newList = currentUniverService.getCurrentUniverHiddenWorksheets().map((s) => ({- label: s.name,- value: s.id,- }));+ const newList = workbook.getHiddenWorksheets();subscriber.next(newList.length === 0);});subscriber.next(hiddenList.length === 0);@@ -1291,9 +1289,9 @@ export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItif (c.id !== SetWorksheetHideCommand.id && c.id !== SetWorksheetShowCommand.id) {return;}- const newList = currentUniverService.getCurrentUniverHiddenWorksheets().map((s) => ({- label: s.name,- value: s.id,+ const newList = workbook.getHiddenWorksheets().map((s) => ({+ label: workbook.getSheetBySheetId(s)?.getName() || '',+ value: s,}));subscriber.next(newList);});