Skip to content

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.

refactor(ui): consolidate ISidebarMethodOptions interface and remove unused files (#4786)

白熱2ac68835740a
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index b122cefa71..aeac5c93f8 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -135,8 +135,7 @@ export { ToolbarButton } from './views/components/ribbon/Button/ToolbarButton';
export { useToolbarItemStatus } from './views/components/ribbon/hook';
export { Ribbon } from './views/components/ribbon/Ribbon';
export { ToolbarItem } from './views/components/ribbon/ToolbarItem';
-export { type ISidebarMethodOptions } from './views/components/sidebar/interface';
-export { Sidebar } from './views/components/sidebar/Sidebar';
+export { type ISidebarMethodOptions, Sidebar } from './views/components/sidebar/Sidebar';
// #endregion
// #region - all commands
diff --git a/packages/ui/src/services/sidebar/desktop-sidebar.service.ts b/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
index 8269b38273..d4b4377b4a 100644
--- a/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
+++ b/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
@@ -15,9 +15,8 @@
*/
import type { IDisposable } from '@univerjs/core';
-import type { ISidebarMethodOptions } from '../../views/components/sidebar/interface';
+import type { ISidebarMethodOptions } from '../../views/components/sidebar/Sidebar';
import type { ISidebarService } from './sidebar.service';
-
import { toDisposable } from '@univerjs/core';
import { Subject } from 'rxjs';
diff --git a/packages/ui/src/services/sidebar/sidebar.service.ts b/packages/ui/src/services/sidebar/sidebar.service.ts
index bdb8cf5d18..fbf39ef2f7 100644
--- a/packages/ui/src/services/sidebar/sidebar.service.ts
+++ b/packages/ui/src/services/sidebar/sidebar.service.ts
@@ -16,8 +16,7 @@
import type { IDisposable } from '@univerjs/core';
import type { Subject } from 'rxjs';
-import type { ISidebarMethodOptions } from '../../views/components/sidebar/interface';
-
+import type { ISidebarMethodOptions } from '../../views/components/sidebar/Sidebar';
import { createIdentifier } from '@univerjs/core';
export interface ISidebarService {
diff --git a/packages/ui/src/views/components/popup/dom-popup.tsx b/packages/ui/src/views/components/popup/dom-popup.tsx
deleted file mode 100644
index cbf7ad3b8c..0000000000
--- a/packages/ui/src/views/components/popup/dom-popup.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * 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 type { IPopup } from '../../../services/popup/canvas-popup.service';
-import React, { useEffect, useMemo, useState } from 'react';
-import { animationFrameScheduler, combineLatest, map, of, throttleTime } from 'rxjs';
-import { useObservableRef } from '../../../utils/di';
-import { RectPopup } from './RectPopup';
-
-interface ISingleDOMPopupProps {
- popup: IPopup;
- children?: React.ReactNode;
-}
-
-/**
- * Align position is diff from SingleCanvasPopup
- */
-const SingleDOMPopup = ({ popup, children }: ISingleDOMPopupProps) => {
- const [hidden, setHidden] = useState(false);
- const anchorRect$ = useMemo(() => popup.anchorRect$.pipe(
- throttleTime(0, animationFrameScheduler),
- map((anchorRect) => {
- const { bottom, left, right, top } = anchorRect;
- const [x = 0, y = 0] = popup.offset ?? [];
- return {
- left: left - x,
- right: right + x,
- top: top - y,
- bottom: bottom + y,
- };
- })
- ), [popup.anchorRect$, popup.offset]);
- const hiddenRects$ = useMemo(() => popup.hiddenRects$?.pipe(throttleTime(0, animationFrameScheduler)) ?? of([]), [popup.hiddenRects$]);
- const excludeRects$ = useMemo(() => popup.excludeRects$?.pipe(throttleTime(0, animationFrameScheduler)), [popup.excludeRects$]);
- const excludeRectsRef = useObservableRef(excludeRects$, popup.excludeRects);
- const { canvasElement, hideOnInvisible = true, hiddenType = 'destroy' } = popup;
-
- useEffect(() => {
- if (!hideOnInvisible) {
- return;
- }
-
- const anchorRectSub = combineLatest([anchorRect$, hiddenRects$]).subscribe(([rectWithOffset, hiddenRects]) => {
- const rect = canvasElement.getBoundingClientRect();
- const { top, left, bottom, right } = rect;
- const rectHeight = rectWithOffset.bottom - rectWithOffset.top;
- const rectWidth = rectWithOffset.right - rectWithOffset.left;
-
- const isInHiddenRect = hiddenRects.some((hiddenRect) => {
- return rectWithOffset.top >= (hiddenRect.top - (0.5 * rectHeight)) &&
- rectWithOffset.bottom <= (hiddenRect.bottom + (0.5 * rectHeight)) &&
- rectWithOffset.left >= (hiddenRect.left - (0.5 * rectWidth)) &&
- rectWithOffset.right <= (hiddenRect.right + (0.5 * rectWidth));
- });
-
- if (rectWithOffset.bottom < top || rectWithOffset.top > bottom || rectWithOffset.right < left || rectWithOffset.left > right || isInHiddenRect) {
- setHidden(true);
- } else {
- setHidden(false);
- }
- });
-
- return () => anchorRectSub.unsubscribe();
- }, [canvasElement, hideOnInvisible, anchorRect$, hiddenRects$]);
- if ((hidden && hiddenType === 'destroy')) {
- return null;
- }
-
- return (
- <RectPopup
- hidden={hidden}
- anchorRect$={anchorRect$}
- direction={popup.direction}
- onClickOutside={popup.onClickOutside}
- excludeOutside={popup.excludeOutside}
- excludeRects={excludeRectsRef}
- onPointerEnter={popup.onPointerEnter}
- onPointerLeave={popup.onPointerLeave}
- onClick={popup.onClick}
- onContextMenu={popup.onContextMenu}
- >
- {children}
- </RectPopup>
- );
-};
-
-export type { ISingleDOMPopupProps };
-export { SingleDOMPopup };
diff --git a/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsx b/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsx
index 9bd2e5c223..aba052f88e 100644
--- a/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsx
+++ b/packages/ui/src/views/components/shortcut-panel/ShortcutPanel.tsx
@@ -85,7 +85,7 @@ export function ShortcutPanel() {
}, [shortcutService, updateShortcuts]);
return (
- <ul className="univer-list-none univer-p-0 univer-text-gray-900">
+ <ul className="univer-m-0 univer-list-none univer-p-0 univer-text-gray-900">
{shortcutItems.map((group) => (
<li key={group.name}>
<div className="univer-flex univer-h-10 univer-items-center univer-text-sm univer-font-semibold">
@@ -95,7 +95,6 @@ export function ShortcutPanel() {
<ul
className={`
univer-list-none univer-p-0
- [&>li:last]:univer-border-b-0
[&>li]:univer-border-0 [&>li]:univer-border-b [&>li]:univer-border-solid
[&>li]:univer-border-b-gray-200
`}
@@ -105,6 +104,7 @@ export function ShortcutPanel() {
key={`${item.title}-${item.shortcut}`}
className={`
univer-flex univer-h-10 univer-items-center univer-justify-between univer-text-[13px]
+ last:univer-border-b-0
`}
>
<span className="univer-line-clamp-1">{item.title}</span>
diff --git a/packages/ui/src/views/components/sidebar/Sidebar.tsx b/packages/ui/src/views/components/sidebar/Sidebar.tsx
index 8f26cade4c..d52b0e1575 100644
--- a/packages/ui/src/views/components/sidebar/Sidebar.tsx
+++ b/packages/ui/src/views/components/sidebar/Sidebar.tsx
@@ -14,14 +14,29 @@
* limitations under the License.
*/
-import type { ISidebarMethodOptions } from './interface';
+import type { CSSProperties } from 'react';
+import type { ICustomLabelProps } from '../../../components/custom-label/CustomLabel';
import { clsx } from '@univerjs/design';
import { CloseSingle } from '@univerjs/icons';
import React, { useEffect, useMemo, useRef } from 'react';
import { CustomLabel } from '../../../components/custom-label/CustomLabel';
import { ISidebarService } from '../../../services/sidebar/sidebar.service';
import { useDependency, useObservable } from '../../../utils/di';
-import styles from './index.module.less';
+
+export interface ISidebarMethodOptions {
+ id?: string;
+ header?: ICustomLabelProps;
+ children?: ICustomLabelProps;
+ bodyStyle?: CSSProperties;
+ footer?: ICustomLabelProps;
+
+ visible?: boolean;
+
+ width?: number | string;
+
+ onClose?: () => void;
+ onOpen?: () => void;
+}
export function Sidebar() {
const sidebarService = useDependency(ISidebarService);
@@ -76,10 +91,6 @@ export function Sidebar() {
};
}, [sidebarService]);
- const _className = clsx(styles.sidebar, {
- [styles.sidebarOpen]: options?.visible,
- });
-
const width = useMemo(() => {
if (!options?.visible) return 0;
@@ -101,19 +112,46 @@ export function Sidebar() {
options?.onClose?.();
}
return (
- <section className={_className} style={{ width }}>
- <section className={styles.sidebarContainer} ref={scrollRef}>
- <header className={styles.sidebarHeader}>
+ <section
+ className={clsx('univer-relative univer-h-full univer-text-gray-800', {
+ 'univer-w-96 univer-translate-x-0': options?.visible,
+ 'univer-w-0 univer-translate-x-full': !options?.visible,
+ })}
+ style={{ width }}
+ >
+ <section
+ className={`
+ univer-box-border univer-grid univer-h-0 univer-min-h-full univer-grid-rows-[auto_1fr_auto]
+ univer-overflow-y-auto univer-border-0 univer-border-b univer-border-l univer-border-solid
+ univer-border-gray-200 univer-bg-white univer-scrollbar-thin univer-scrollbar-track-gray-50
+ univer-scrollbar-thumb-gray-300
+ `}
+ ref={scrollRef}
+ >
+ <header
+ className={`
+ univer-sticky univer-top-0 univer-z-10 univer-box-border univer-flex univer-items-center
+ univer-justify-between univer-bg-white univer-p-4 univer-pb-2 univer-text-base univer-font-medium
+ `}
+ >
{options?.header}
- <a className={styles.sidebarHeaderClose} onClick={handleClose}>
+ <a className="univer-cursor-pointer univer-text-gray-500" onClick={handleClose}>
<CloseSingle />
</a>
</header>
- <section className={clsx(styles.sidebarBody, 'univer-py-1')} style={options?.bodyStyle}>{options?.children}</section>
-
- {options?.footer && <footer className={styles.sidebarFooter}>{options.footer}</footer>}
+ <section className="univer-box-border univer-px-4" style={options?.bodyStyle}>
+ {options?.children}
+ </section>
+
+ {options?.footer && (
+ <footer
+ className="univer-sticky univer-bottom-0 univer-box-border univer-bg-white univer-p-4"
+ >
+ {options.footer}
+ </footer>
+ )}
</section>
</section>
);
diff --git a/packages/ui/src/views/components/sidebar/index.module.less b/packages/ui/src/views/components/sidebar/index.module.less
deleted file mode 100644
index 51fd9b6266..0000000000
--- a/packages/ui/src/views/components/sidebar/index.module.less
+++ /dev/null
@@ -1,72 +0,0 @@
-.sidebar {
- position: relative;
- transform: translateX(100%);
-
- box-sizing: border-box;
- width: 0;
- height: 100%;
-
- color: rgb(var(--text-color));
-
- &&-open {
- transform: translateX(0);
- width: 380px;
- }
-
- &-container {
- overflow-y: auto;
- display: grid;
- grid-template-rows: auto 1fr auto;
-
- box-sizing: border-box;
- width: 100%;
- height: 0;
- min-height: 100%;
- margin: auto;
-
- background-color: rgb(var(--bg-color-secondary));
- border-bottom: 1px solid rgb(var(--border-color));
- border-left: 1px solid rgb(var(--border-color));
-
- scrollbar-color: rgba(var(--scrollbar-color), 0.7) transparent;
- scrollbar-gutter: auto;
- scrollbar-width: thin;
- }
-
- &-header {
- position: sticky;
- top: 0;
-
- display: flex;
- align-items: center;
- justify-content: space-between;
-
- height: 44px;
- padding: var(--padding-xl) var(--padding-xl) 0;
-
- font-size: var(--font-size-lg);
- font-weight: 500;
-
- background: rgb(var(--bg-color-secondary));
- box-sizing: border-box;
- z-index: 10;
-
- &-close {
- cursor: pointer;
- color: rgb(var(--text-color-secondary));
- }
- }
-
- &-body {
- padding: 0 var(--padding-xl);
- box-sizing: border-box;
- }
-
- &-footer {
- position: sticky;
- bottom: 0;
- padding: var(--padding-xl);
- background: rgb(var(--bg-color-secondary));
- box-sizing: border-box;
- }
-}
diff --git a/packages/ui/src/views/components/sidebar/interface.ts b/packages/ui/src/views/components/sidebar/interface.ts
deleted file mode 100644
index e2797746fb..0000000000
--- a/packages/ui/src/views/components/sidebar/interface.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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 type { CSSProperties } from 'react';
-import type { ICustomLabelProps } from '../../../components/custom-label/CustomLabel';
-
-export interface ISidebarMethodOptions {
- id?: string;
- header?: ICustomLabelProps;
- children?: ICustomLabelProps;
- bodyStyle?: CSSProperties;
- footer?: ICustomLabelProps;
-
- visible?: boolean;
-
- width?: number | string;
-
- onClose?: () => void;
- onOpen?: () => void;
-}