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
feat(sheets-ui): support embedded presentation tabs (#7487)
Univerfa702adaab08
diff --git a/packages/sheets-ui/src/__tests__/embed-tab-anchor.spec.ts b/packages/sheets-ui/src/__tests__/embed-tab-anchor.spec.tsnew file mode 100644index 0000000000..0b2753c004--- /dev/null+++ b/packages/sheets-ui/src/__tests__/embed-tab-anchor.spec.ts@@ -0,0 +1,40 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { UniverInstanceType } from '@univerjs/core';+import { describe, expect, it } from 'vitest';++import { getEmbedSheetsTabCustomData } from '../embed-tab-anchor';++describe('getEmbedSheetsTabCustomData', () => {+ it('reads the embedded product type used by the Sheet tab marker', () => {+ expect(getEmbedSheetsTabCustomData({+ custom: {+ UNIVER_EMBED_SHEETS_TAB: {+ version: 1,+ embedId: 'embed-1',+ hostAnchorId: 'sheet-1',+ childType: UniverInstanceType.UNIVER_BOARD,+ },+ },+ })).toEqual({+ version: 1,+ embedId: 'embed-1',+ hostAnchorId: 'sheet-1',+ childType: UniverInstanceType.UNIVER_BOARD,+ });+ });+});diff --git a/packages/sheets-ui/src/embed-tab-anchor.ts b/packages/sheets-ui/src/embed-tab-anchor.tsindex 1c1601fe91..685af8d8b3 100644--- a/packages/sheets-ui/src/embed-tab-anchor.ts+++ b/packages/sheets-ui/src/embed-tab-anchor.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IWorksheetData } from '@univerjs/core';+import type { IWorksheetData, UniverInstanceType } from '@univerjs/core';const EMBED_SHEETS_TAB_CUSTOM_KEY = 'UNIVER_EMBED_SHEETS_TAB';@@ -22,6 +22,7 @@ interface IEmbedSheetsTabCustomData {version: 1;embedId: string;hostAnchorId: string;+ childType?: UniverInstanceType;}export function getEmbedSheetsTabCustomData(snapshot: Pick<IWorksheetData, 'custom'>): IEmbedSheetsTabCustomData | undefined {@@ -41,5 +42,6 @@ function isEmbedSheetsTabCustomData(value: unknown): value is IEmbedSheetsTabCusconst candidate = value as Partial<IEmbedSheetsTabCustomData>;return candidate.version === 1 &&typeof candidate.embedId === 'string' &&- typeof candidate.hostAnchorId === 'string';+ typeof candidate.hostAnchorId === 'string' &&+ (candidate.childType === undefined || typeof candidate.childType === 'number');}diff --git a/packages/sheets-ui/src/services/sheet-embed-runtime.service.ts b/packages/sheets-ui/src/services/sheet-embed-runtime.service.tsindex 84a22912b3..8da5ca2eff 100644--- a/packages/sheets-ui/src/services/sheet-embed-runtime.service.ts+++ b/packages/sheets-ui/src/services/sheet-embed-runtime.service.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IDisposable } from '@univerjs/core';+import type { IDisposable, UniverInstanceType } from '@univerjs/core';import { createIdentifier } from '@univerjs/core';export interface ISheetEmbedTabMountParams {@@ -25,6 +25,7 @@ export interface ISheetEmbedTabMountParams {export interface ISheetEmbedRuntimeService {mountSheetTab(params: ISheetEmbedTabMountParams): IDisposable | undefined;+ getSheetTabChildType?(params: ISheetEmbedTabMountParams): UniverInstanceType | undefined;clearTab(embedId?: string): void;}diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsxindex e57f30d88f..a79212eb7f 100644--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx@@ -23,13 +23,22 @@ import type { IBaseSheetBarProps } from './SheetBarItem';import {ICommandService,IConfirmService,+ Injector,IPermissionService,LocaleService,nameCharacterCheck,Quantity,+ UniverInstanceType,} from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';-import { LockIcon } from '@univerjs/icons';+import {+ BasesMultiIcon,+ BoardsMultiIcon,+ DocsMultiIcon,+ LockIcon,+ SheetsMultiIcon,+ SlidesMultiIcon,+} from '@univerjs/icons';import {InsertSheetMutation,RangeProtectionRuleModel,@@ -48,8 +57,10 @@ import {import { UI_PLUGIN_CONFIG_KEY, useConfigValue, useDependency, useObservable } from '@univerjs/ui';import { useCallback, useEffect, useRef, useState } from 'react';import { merge } from 'rxjs';+import { getEmbedSheetsTabCustomData } from '../../../embed-tab-anchor';import { IEditorBridgeService } from '../../../services/editor-bridge.service';import { ISheetBarService } from '../../../services/sheet-bar/sheet-bar.service';+import { ISheetEmbedRuntimeService } from '../../../services/sheet-embed-runtime.service';import { SheetSkeletonManagerService } from '../../../services/sheet-skeleton-manager.service';import { useActiveWorkbook } from '../../hook';import { SheetBarItem } from './SheetBarItem';@@ -68,6 +79,29 @@ interface IContextMenuAnchorRect {bottom: number;}+interface IEmbedSheetTabProductIconProps {+ childType: UniverInstanceType;+}++function EmbedSheetTabProductIcon({ childType }: IEmbedSheetTabProductIconProps) {+ const className = 'univer-size-4 univer-shrink-0';++ switch (childType) {+ case UniverInstanceType.UNIVER_SHEET:+ return <SheetsMultiIcon aria-hidden className={className} />;+ case UniverInstanceType.UNIVER_DOC:+ return <DocsMultiIcon aria-hidden className={className} />;+ case UniverInstanceType.UNIVER_SLIDE:+ return <SlidesMultiIcon aria-hidden className={className} />;+ case UniverInstanceType.UNIVER_BASE:+ return <BasesMultiIcon aria-hidden className={className} />;+ case UniverInstanceType.UNIVER_BOARD:+ return <BoardsMultiIcon aria-hidden className={className} />;+ default:+ return null;+ }+}+function getScrollShadow(state: IScrollState) {const { leftEnd, rightEnd } = state;@@ -102,6 +136,7 @@ function shouldRefreshSheetTabs(commandInfo: ICommandInfo) {}export function SheetBarTabs() {+ const injector = useDependency(Injector);const [sheetList, setSheetList] = useState<IBaseSheetBarProps[]>([]);const [activeSheetId, setActiveSheetId] = useState('');const [scrollShadow, setScrollShadow] = useState('');@@ -245,6 +280,9 @@ export function SheetBarTabs() {const updateSheetItems = useCallback(() => {const activeSheet = workbook.getActiveSheet();const currentSubUnitId = activeSheet?.getSheetId() ?? '';+ const embedRuntimeService = injector.has(ISheetEmbedRuntimeService)+ ? injector.get(ISheetEmbedRuntimeService)+ : undefined;const sheetListItems = workbook.getSheets()@@ -253,17 +291,24 @@ export function SheetBarTabs() {const worksheetRule = worksheetProtectionRuleModel.getRule(workbook.getUnitId(), sheet.getSheetId());const hasSelectionRule = rangeProtectionRuleModel.getSubunitRuleList(workbook.getUnitId(), sheet.getSheetId()).length > 0;const hasProtection = Boolean(worksheetRule?.permissionId || hasSelectionRule);+ const embedData = getEmbedSheetsTabCustomData(sheet.getConfig());+ const embedChildType = embedData?.childType ?? (embedData+ ? embedRuntimeService?.getSheetTabChildType?.({+ hostUnitId: workbook.getUnitId(),+ hostAnchorId: embedData.hostAnchorId,+ embedId: embedData.embedId,+ })+ : undefined);return {sheetId: sheet.getSheetId(),- label: hasProtection- ? (- <>- <LockIcon className="univer-shrink-0" />- <span className="univer-truncate univer-outline-none">{sheet.getName()}</span>- </>- )- : <span className="univer-truncate univer-outline-none">{sheet.getName()}</span>,+ label: (+ <>+ {embedChildType != null && <EmbedSheetTabProductIcon childType={embedChildType} />}+ {hasProtection && <LockIcon className="univer-shrink-0" />}+ <span className="univer-truncate univer-outline-none">{sheet.getName()}</span>+ </>+ ),index,selected: activeSheet === sheet,color: sheet.getTabColor() ?? undefined,@@ -274,7 +319,7 @@ export function SheetBarTabs() {setSheetList(sheetListItems);// eslint-disable-next-line react/set-state-in-effectsetActiveSheetId(currentSubUnitId);- }, [rangeProtectionRuleModel, workbook, worksheetProtectionRuleModel]);+ }, [injector, rangeProtectionRuleModel, workbook, worksheetProtectionRuleModel]);const setTabEditor = useCallback(() => {slideTabBarRef.current?.getActiveItem()?.setEditor();