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: refactor Message component (#4352)

白熱232f8dc4b6f8
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 1660b60941..0878774491 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -188,5 +188,9 @@
"toml",
"less",
"css"
- ]
+ ],
+
+ "editor.quickSuggestions": {
+ "strings": "on"
+ }
}
diff --git a/common/shared/eslint/index.js b/common/shared/eslint/index.js
index 18d1c12030..2ad60afe49 100644
--- a/common/shared/eslint/index.js
+++ b/common/shared/eslint/index.js
@@ -196,7 +196,7 @@ exports.tailwindcssPreset = () => {
...eslintPluginReadableTailwind.configs.warning.rules,
...eslintPluginReadableTailwind.configs.error.rules,
'jsonc/sort-keys': ['warn'],
- 'readable-tailwind/multiline': ['warn', { printWidth: 120 }],
+ 'readable-tailwind/multiline': ['warn', { printWidth: 120, group: 'newLine' }],
'react-hooks/rules-of-hooks': 'off',
},
};
diff --git a/common/shared/package.json b/common/shared/package.json
index df497ef865..5568b9634a 100644
--- a/common/shared/package.json
+++ b/common/shared/package.json
@@ -34,6 +34,7 @@
"javascript-obfuscator": "^4.1.1",
"sort-keys": "^5.1.0",
"tailwindcss": "^3.4.16",
+ "tailwindcss-animate": "^1.0.7",
"vite": "^6.0.3",
"vite-plugin-dts": "^4.3.0",
"vite-plugin-external": "^4.3.1",
diff --git a/common/shared/tailwind/tailwind.config.ts b/common/shared/tailwind/tailwind.config.ts
index a27ec9eb47..21293bd65a 100644
--- a/common/shared/tailwind/tailwind.config.ts
+++ b/common/shared/tailwind/tailwind.config.ts
@@ -15,9 +15,14 @@
*/
import type { Config } from 'tailwindcss';
+import animate from 'tailwindcss-animate';
const config: Omit<Config, 'content'> = {
prefix: 'univer-',
+ darkMode: 'selector',
+ corePlugins: {
+ preflight: false,
+ },
theme: {
extend: {
colors: {
@@ -156,7 +161,9 @@ const config: Omit<Config, 'content'> = {
},
},
},
- plugins: [],
+ plugins: [
+ animate,
+ ],
};
export default config;
diff --git a/common/storybook/.storybook/global.css b/common/storybook/.storybook/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/common/storybook/.storybook/global.css
+++ b/common/storybook/.storybook/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/common/storybook/.storybook/preview.tsx b/common/storybook/.storybook/preview.tsx
index 47f357a258..0d849af595 100644
--- a/common/storybook/.storybook/preview.tsx
+++ b/common/storybook/.storybook/preview.tsx
@@ -45,7 +45,7 @@ import { ConfigProvider, defaultTheme, greenTheme, themeInstance } from '@univer
import enUS from '@univerjs/design/locale/en-US';
import zhCN from '@univerjs/design/locale/zh-CN';
import { DesktopLocalStorageService } from '@univerjs/ui';
-import React from 'react';
+import React, { useMemo } from 'react';
import './global.css';
@@ -86,33 +86,55 @@ const preview: Preview = {
showName: true,
},
},
+ darkMode: {
+ name: 'darkMode',
+ description: 'Dark mode',
+ defaultValue: 'light',
+ toolbar: {
+ icon: 'sun',
+ items: ['light', 'dark'],
+ showName: true,
+ },
+ },
},
decorators: [(Story, context) => {
- const injector = new Injector([
- [IUniverInstanceService, { useClass: UniverInstanceService }],
- [ErrorService],
- [LocaleService],
- [ThemeService],
- [LifecycleService],
- [ILogService, { useClass: DesktopLogService, lazy: true }],
- [ICommandService, { useClass: CommandService, lazy: true }],
- [IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],
- [IConfigService, { useClass: ConfigService }],
- [IContextService, { useClass: ContextService }],
- [IResourceManagerService, { useClass: ResourceManagerService, lazy: true }],
- [IPermissionService, { useClass: PermissionService }],
-
- // services
- [ILocalStorageService, { useClass: DesktopLocalStorageService, lazy: true }],
- ]);
-
- injector.get(LocaleService).setLocale(context.globals.i18n);
themeInstance.setTheme(document.body, themes[context.globals.theme]);
const designLocale = context.globals.i18n === LocaleType.ZH_CN ? zhCN.design : enUS.design;
+ if (context.globals.darkMode === 'dark') {
+ document.body.classList.add('univer-dark');
+ } else {
+ document.body.classList.remove('univer-dark');
+ }
+
+ const rediContext = useMemo(() => {
+ const injector = new Injector([
+ [IUniverInstanceService, { useClass: UniverInstanceService }],
+ [ErrorService],
+ [LocaleService],
+ [ThemeService],
+ [LifecycleService],
+ [ILogService, { useClass: DesktopLogService, lazy: true }],
+ [ICommandService, { useClass: CommandService, lazy: true }],
+ [IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],
+ [IConfigService, { useClass: ConfigService }],
+ [IContextService, { useClass: ContextService }],
+ [IResourceManagerService, { useClass: ResourceManagerService, lazy: true }],
+ [IPermissionService, { useClass: PermissionService }],
+
+ // services
+ [ILocalStorageService, { useClass: DesktopLocalStorageService, lazy: true }],
+ ]);
+
+ injector.get(LocaleService).setLocale(context.globals.i18n);
+ return {
+ injector,
+ };
+ }, []);
+
return (
- <RediContext.Provider value={{ injector }}>
+ <RediContext.Provider value={rediContext}>
<ConfigProvider locale={designLocale} mountContainer={document.body}>
<Story />
</ConfigProvider>
diff --git a/examples/esbuild.config.ts b/examples/esbuild.config.ts
index 9fdb29ee03..75060e7b40 100644
--- a/examples/esbuild.config.ts
+++ b/examples/esbuild.config.ts
@@ -114,47 +114,48 @@ const config: SameShape<BuildOptions, BuildOptions> = {
sourcemap: args.watch,
minify: false,
target: 'chrome70',
- plugins: [{
- name: 'ignore-global-css',
- setup(build) {
- build.onResolve({ filter: /\/global\.css$/ }, (args) => {
- if (args.importer.includes('packages')) {
- return {
- path: args.path,
- namespace: 'ignore-global-css',
- pluginData: {
- importer: args.importer,
- },
- };
- }
- });
-
- build.onLoad({ filter: /\/global\.css$/, namespace: 'ignore-global-css' }, () => {
- return { contents: '' };
- });
- },
- },
- copyPlugin({
- assets: {
- from: ['./public/**/*'],
- to: ['./'],
- },
- }),
- stylePlugin({
- postcss: {
- plugins: [tailwindcss],
- },
- cssModulesOptions: {
- localsConvention: 'camelCaseOnly',
- generateScopedName: 'univer-[local]',
- },
- renderOptions: {
- lessOptions: {
- paths: [nodeModules],
+ plugins: [
+ {
+ name: 'ignore-global-css',
+ setup(build) {
+ build.onResolve({ filter: /\/global\.css$/ }, (args) => {
+ if (args.importer.includes('packages')) {
+ return {
+ path: args.path,
+ namespace: 'ignore-global-css',
+ pluginData: {
+ importer: args.importer,
+ },
+ };
+ }
+ });
+
+ build.onLoad({ filter: /\/global\.css$/, namespace: 'ignore-global-css' }, () => {
+ return { contents: '' };
+ });
},
},
- }),
- vue() as unknown as Plugin,
+ copyPlugin({
+ assets: {
+ from: ['./public/**/*'],
+ to: ['./'],
+ },
+ }),
+ stylePlugin({
+ postcss: {
+ plugins: [tailwindcss],
+ },
+ cssModulesOptions: {
+ localsConvention: 'camelCaseOnly',
+ generateScopedName: 'univer-[local]',
+ },
+ renderOptions: {
+ lessOptions: {
+ paths: [nodeModules],
+ },
+ },
+ }),
+ vue() as unknown as Plugin,
],
entryPoints,
outdir: './local',
diff --git a/examples/src/global.css b/examples/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/examples/src/global.css
+++ b/examples/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/action-recorder/src/global.css b/packages-experimental/action-recorder/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages-experimental/action-recorder/src/global.css
+++ b/packages-experimental/action-recorder/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/debugger/src/commands/operations/message.operation.ts b/packages-experimental/debugger/src/commands/operations/message.operation.ts
index 67acb6aa29..621cd4d53e 100644
--- a/packages-experimental/debugger/src/commands/operations/message.operation.ts
+++ b/packages-experimental/debugger/src/commands/operations/message.operation.ts
@@ -14,10 +14,10 @@
* limitations under the License.
*/
+import type { IAccessor, ICommand } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { IMessageService } from '@univerjs/ui';
-import type { IAccessor, ICommand } from '@univerjs/core';
export const MessageOperation: ICommand = {
id: 'debugger.operation.message',
@@ -25,8 +25,9 @@ export const MessageOperation: ICommand = {
handler: async (accessor: IAccessor) => {
const messageService = accessor.get(IMessageService);
messageService.show({
- type: MessageType.Error,
+ type: MessageType.Success,
content: 'Demo message',
+ duration: 1500,
});
return true;
diff --git a/packages-experimental/debugger/src/global.css b/packages-experimental/debugger/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages-experimental/debugger/src/global.css
+++ b/packages-experimental/debugger/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/uni-docs-ui/src/global.css b/packages-experimental/uni-docs-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages-experimental/uni-docs-ui/src/global.css
+++ b/packages-experimental/uni-docs-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/uni-formula-ui/src/global.css b/packages-experimental/uni-formula-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages-experimental/uni-formula-ui/src/global.css
+++ b/packages-experimental/uni-formula-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/uni-sheets-ui/src/global.css b/packages-experimental/uni-sheets-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages-experimental/uni-sheets-ui/src/global.css
+++ b/packages-experimental/uni-sheets-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/uni-slides-ui/src/global.css b/packages-experimental/uni-slides-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages-experimental/uni-slides-ui/src/global.css
+++ b/packages-experimental/uni-slides-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/uniui/src/global.css b/packages-experimental/uniui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages-experimental/uniui/src/global.css
+++ b/packages-experimental/uniui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages-experimental/uniui/src/views/workbench/UniWorkbench.tsx b/packages-experimental/uniui/src/views/workbench/UniWorkbench.tsx
index 5dc77085ac..05e8a11571 100644
--- a/packages-experimental/uniui/src/views/workbench/UniWorkbench.tsx
+++ b/packages-experimental/uniui/src/views/workbench/UniWorkbench.tsx
@@ -31,7 +31,6 @@ import {
BuiltInUIPart,
ComponentContainer,
ContextMenu,
- IMessageService,
type IWorkbenchOptions,
UNI_DISABLE_CHANGING_FOCUS_KEY,
useComponentsOfPart,
@@ -76,7 +75,6 @@ export function UniWorkbench(props: IUniWorkbenchProps) {
const localeService = useDependency(LocaleService);
const themeService = useDependency(ThemeService);
- const messageService = useDependency(IMessageService);
const unitGridService = useDependency(IUnitGridService);
const instanceService = useDependency(IUniverInstanceService);
const renderManagerService = useDependency(IRenderManagerService);
@@ -127,7 +125,6 @@ export function UniWorkbench(props: IUniWorkbenchProps) {
useEffect(() => {
document.body.appendChild(portalContainer);
- messageService.setContainer(portalContainer);
const subscriptions = [
localeService.localeChanged$.subscribe(() => {
@@ -146,7 +143,7 @@ export function UniWorkbench(props: IUniWorkbenchProps) {
// cleanup
document.body.removeChild(portalContainer);
};
- }, [localeService, messageService, mountContainer, portalContainer, themeService.currentTheme$]);
+ }, [localeService, mountContainer, portalContainer, themeService.currentTheme$]);
const nodeTypes: NodeTypes = {
customNode: UnitNode,
diff --git a/packages/design/package.json b/packages/design/package.json
index 18347ee2e0..9527dfc643 100644
--- a/packages/design/package.json
+++ b/packages/design/package.json
@@ -89,7 +89,8 @@
"react-draggable": "^4.4.6",
"react-grid-layout": "^1.5.0",
"react-mentions": "^4.4.10",
- "react-transition-group": "^4.4.5"
+ "react-transition-group": "^4.4.5",
+ "tailwind-merge": "^2.5.5"
},
"devDependencies": {
"@testing-library/react": "^16.0.1",
diff --git a/packages/design/src/components/message/Message.stories.tsx b/packages/design/src/components/message/Message.stories.tsx
index d24b78054a..b226df4cf0 100644
--- a/packages/design/src/components/message/Message.stories.tsx
+++ b/packages/design/src/components/message/Message.stories.tsx
@@ -18,7 +18,7 @@ import type { Meta } from '@storybook/react';
import React from 'react';
import { Button } from '../button/Button';
-import { Message, MessageType } from './Message';
+import { message, Messager, MessageType } from './Message';
const meta: Meta = {
title: 'Components / Message',
@@ -33,29 +33,33 @@ export default meta;
export const Playground = {
render: () => {
- const message = new Message(document.body);
-
function handleOpen(type: MessageType) {
- message[type]({
+ message({
+ type,
content: 'Hello world!',
});
}
return (
- <>
+ <section className="univer-space-x-2">
<Button type="primary" onClick={() => handleOpen(MessageType.Success)}>
- Click Me
+ success
</Button>
<Button type="primary" onClick={() => handleOpen(MessageType.Info)}>
- Click Me
+ info / default
</Button>
<Button type="primary" onClick={() => handleOpen(MessageType.Warning)}>
- Click Me
+ warning
</Button>
<Button type="primary" onClick={() => handleOpen(MessageType.Error)}>
- Click Me
+ error
+ </Button>
+ <Button type="primary" onClick={() => handleOpen(MessageType.Loading)}>
+ loading
</Button>
- </>
+
+ <Messager />
+ </section>
);
},
};
diff --git a/packages/design/src/components/message/Message.tsx b/packages/design/src/components/message/Message.tsx
index c42cc6d173..cca546fd0e 100644
--- a/packages/design/src/components/message/Message.tsx
+++ b/packages/design/src/components/message/Message.tsx
@@ -14,17 +14,11 @@
* limitations under the License.
*/
-/* eslint-disable react-refresh/only-export-components */
-
-import type { CSSProperties, ReactElement } from 'react';
-import type { IDisposable } from '../../type';
-import { ErrorSingle, Loading, SuccessSingle, WarningSingle } from '@univerjs/icons';
+import { ErrorSingle, InfoSingle, Loading, SuccessSingle, WarningSingle } from '@univerjs/icons';
import canUseDom from 'rc-util/lib/Dom/canUseDom';
-import { render, unmount } from 'rc-util/lib/React/render';
-import React from 'react';
-import { CSSTransition, TransitionGroup } from 'react-transition-group';
-
-import styles from './index.module.less';
+import React, { useEffect, useMemo, useState } from 'react';
+import { createPortal } from 'react-dom';
+import clsx from '../../helper/clsx';
export enum MessageType {
Success = 'success',
@@ -35,142 +29,127 @@ export enum MessageType {
}
export interface IMessageProps {
- key: string;
- type: MessageType;
+ id?: string;
content: string;
- icon?: ReactElement;
- style?: CSSProperties;
-}
-
-export interface IMessageOptions extends
- Partial<Pick<IMessageProps, 'key' | 'type'>>,
- Pick<IMessageProps, 'content'> {
-
- /**
- * After `duration` milliseconds, the message would be removed automatically. However, if `duration` is set to 0,
- * the message would not be removed automatically.
- */
duration?: number;
+ type?: MessageType;
+ onClose?: () => void;
}
const iconMap = {
- [MessageType.Success]: <SuccessSingle className={styles.messageIconSuccess} />,
- [MessageType.Info]: <WarningSingle className={styles.messageIconInfo} />,
- [MessageType.Warning]: <WarningSingle className={styles.messageIconWarning} />,
- [MessageType.Error]: <ErrorSingle className={styles.messageIconError} />,
- [MessageType.Loading]: <Loading className={styles.messageIconError} />,
+ [MessageType.Success]: <SuccessSingle className="univer-text-green-500" />,
+ [MessageType.Info]: <InfoSingle className="univer-text-indigo-600 dark:univer-text-primary-500" />,
+ [MessageType.Warning]: <WarningSingle className="univer-text-yellow-400" />,
+ [MessageType.Error]: <ErrorSingle className="univer-text-red-500" />,
+ [MessageType.Loading]: <Loading className="univer-text-yellow-400 univer-animate-spin" />,
};
-const MessageItem = (props: IMessageProps) => {
- const { type, content, icon, style } = props;
-
- const messageElement = (
- <div className={styles.messageItem} style={style}>
- <div className={styles.messageContent}>
- <span className={styles.messageIcon}>{icon || iconMap[type]}</span>
- <span>{content}</span>
- </div>
- </div>
- );
-
- return messageElement;
-};
-
-const MessageContainer = (props: { messages: IMessageProps[] }) => {
- const { messages } = props;
-
+// eslint-disable-next-line react-refresh/only-export-components
+const Message = ({ content, type = MessageType.Info }: IMessageProps) => {
+ const icon = useMemo(() => iconMap[type], [type]);
return (
- <TransitionGroup className={styles.message}>
- {messages.map((message) => (
- <CSSTransition
- key={message.key}
- timeout={200}
- classNames={{
- enterActive: styles.enterActive,
- enterDone: styles.enterDone,
- exitActive: styles.exit,
- exitDone: styles.exitActive,
- }}
+ <div
+ className={clsx(
+ `
+ univer-rounded-xl univer-p-4 univer-min-w-[320px] univer-transition-all univer-bg-white
+ univer-duration-300 univer-animate-in univer-fade-in univer-slide-in-from-top-4 univer-shadow-md
+ univer-max-w-[480px] univer-border univer-border-gray-200 univer-border-solid
+ dark:univer-border-gray-700 dark:univer-bg-gray-700
+ `
+ )}
+ >
+ <div className="univer-flex univer-gap-2 univer-items-start">
+ <span className="[&>svg]:univer-relative [&>svg]:univer-top-0.5 [&>svg]:univer-block">
+ {icon}
+ </span>
+ <p
+ className={`
+ univer-text-sm univer-opacity-90 univer-m-0 univer-text-gray-500
+ dark:univer-text-gray-400
+ `}
>
- <MessageItem {...message} />
- </CSSTransition>
- ))}
- </TransitionGroup>
+ {content}
+ </p>
+ </div>
+ </div>
);
};
-export class Message implements IDisposable {
- protected _container: HTMLDivElement;
+interface IMessageState {
+ messages: IMessageProps[];
+}
- protected _messages: IMessageProps[] = [];
+let messageCount = 0;
- constructor(container: HTMLElement) {
- if (canUseDom()) {
- this._container = document.createElement('div');
- container.appendChild(this._container);
- } else {
- this._container = container as HTMLDivElement;
- }
+const createMessage = (() => {
+ let addMessage: (message: Omit<IMessageProps, 'id'>) => void = () => {};
+ let removeMessage: (id?: string) => void = () => {};
- this.render();
- }
-
- dispose(): void {
- unmount(this._container);
- this._container.remove();
- }
-
- append(type: MessageType, options: IMessageOptions): IDisposable {
- const { content, duration = 3000, key = `${Date.now()}` } = options;
-
- const existingMessage = this._messages.findIndex((message) => message.key === options.key);
- if (existingMessage !== -1) {
- this._messages[existingMessage].content = content;
- this._messages[existingMessage].type = type;
- } else {
- this._messages.push({
- key,
- type,
- content,
- });
+ const Messager = () => {
+ if (!canUseDom()) {
+ return null;
}
- this.render();
-
- if (duration !== 0) {
- setTimeout(() => this.teardown(key), duration);
- }
-
- return { dispose: () => this.teardown(key) };
- }
-
- teardown(key: string) {
- this._messages = this._messages.filter((message) => message.key !== key);
-
- this.render();
- }
-
- render() {
- render(<MessageContainer messages={this._messages} />, this._container);
- }
-
- success(options: IMessageOptions): IDisposable {
- return this.append(MessageType.Success, options);
- }
-
- info(options: IMessageOptions): IDisposable {
- return this.append(MessageType.Info, options);
- }
-
- warning(options: IMessageOptions): IDisposable {
- return this.append(MessageType.Warning, options);
- }
-
- error(options: IMessageOptions): IDisposable {
- return this.append(MessageType.Error, options);
- }
-
- loading(options: IMessageOptions): IDisposable {
- return this.append(MessageType.Loading, options);
- }
-}
+ const [state, setState] = useState<IMessageState>({ messages: [] });
+
+ removeMessage = (id?: string) => {
+ if (!id) {
+ setState({
+ messages: [],
+ });
+ }
+
+ setState((prev) => ({
+ messages: prev.messages.filter((t) => t.id !== id),
+ }));
+ };
+
+ useEffect(() => {
+ addMessage = (message) => {
+ const id = String(messageCount++);
+ setState((prev) => ({
+ messages: [...prev.messages, { ...message, id }],
+ }));
+
+ if (message.duration !== Infinity) {
+ setTimeout(() => {
+ setState((prev) => ({
+ messages: prev.messages.filter((t) => t.id !== id),
+ }));
+ }, message.duration || 3000);
+ }
+ };
+ }, []);
+
+ return createPortal(
+ <div
+ className={`
+ univer-fixed univer-left-1/2 univer-top-4 univer-z-50 univer-flex univer-flex-col univer-items-center
+ univer-gap-1 -univer-translate-x-1/2
+ `}
+ >
+ {state.messages.map((message, index) => (
+ <div
+ key={message.id}
+ style={{
+ position: 'relative',
+ top: `${index * 4}px`,
+ zIndex: 50 - index,
+ }}
+ >
+ <Message {...message} onClose={() => removeMessage(message.id)} />
+ </div>
+ ))}
+ </div>,
+ document.body
+ );
+ };
+
+ return {
+ Messager,
+ message: (props: Omit<IMessageProps, 'id'>) => addMessage(props),
+ removeMessage,
+ };
+})();
+
+export const { Messager, message, removeMessage } = createMessage;
diff --git a/packages/design/src/components/message/__tests__/index.spec.tsx b/packages/design/src/components/message/__tests__/index.spec.tsx
index 5b824dd81c..6ac2d4aa14 100644
--- a/packages/design/src/components/message/__tests__/index.spec.tsx
+++ b/packages/design/src/components/message/__tests__/index.spec.tsx
@@ -19,22 +19,24 @@ import React from 'react';
import { describe, expect, it } from 'vitest';
import { Button } from '../../button/Button';
-import { Message } from '../Message';
+import { message, Messager, MessageType } from '../Message';
describe('Message', () => {
it('renders correctly', () => {
- const message = new Message(document.body);
-
const { container } = render(
- <Button
- onClick={() => {
- message.success({
- content: 'success content',
- });
- }}
- >
- btn2
- </Button>
+ <>
+ <Button
+ onClick={() => {
+ message({
+ type: MessageType.Success,
+ content: 'success content',
+ });
+ }}
+ >
+ btn2
+ </Button>
+ <Messager />
+ </>
);
fireEvent.click(container.querySelector('button')!);
diff --git a/packages/design/src/components/message/index.module.less b/packages/design/src/components/message/index.module.less
deleted file mode 100644
index 49496f2b5e..0000000000
--- a/packages/design/src/components/message/index.module.less
+++ /dev/null
@@ -1,73 +0,0 @@
-.message {
- position: fixed;
- z-index: 1000;
- top: var(--margin-sm);
- left: 50%;
- transform: translateX(-50%);
-
- display: grid;
- gap: var(--margin-sm);
-
- &-item {
- display: flex;
- justify-content: center;
- opacity: 0;
- transition: all 0.2s cubic-bezier(0.1, 0.7, 1, 0.1);
-
- &.enter-active {
- transform: translateY(-20px);
- opacity: 0;
- }
-
- &.enter-done {
- transform: translateY(0);
- opacity: 1;
- }
-
- &.exit {
- transform: translateY(-20px);
- margin-bottom: -40px;
- opacity: 0;
- }
-
- &.exit-active {
- transform: translateY(-20px);
- opacity: 0;
- }
- }
-
- &-icon {
- display: inline-flex;
- align-items: center;
-
- &-success {
- color: rgb(var(--success-color));
- }
-
- &-info {
- color: rgb(var(--info-color));
- }
-
- &-warning {
- color: rgb(var(--warning-color));
- }
-
- &-error {
- color: rgb(var(--error-color));
- }
- }
-
- &-content {
- display: inline-flex;
- gap: var(--margin-xs);
- align-items: center;
-
- padding: var(--padding-base);
-
- font-size: var(--font-size-base);
-
- background-color: rgb(var(--color-white));
- border-radius: var(--border-radius-base);
- box-shadow: var(--box-shadow-lg);
- }
-}
diff --git a/packages/design/src/components/message/index.ts b/packages/design/src/components/message/index.ts
index a6382e1a6c..42fd06ea09 100644
--- a/packages/design/src/components/message/index.ts
+++ b/packages/design/src/components/message/index.ts
@@ -14,4 +14,4 @@
* limitations under the License.
*/
-export { type IMessageOptions, type IMessageProps, Message, MessageType } from './Message';
+export { type IMessageProps, message, Messager, MessageType, removeMessage } from './Message';
diff --git a/packages/design/src/global.css b/packages/design/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/design/src/global.css
+++ b/packages/design/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/design/src/helper/clsx.tsx b/packages/design/src/helper/clsx.tsx
new file mode 100644
index 0000000000..6b95932e42
--- /dev/null
+++ b/packages/design/src/helper/clsx.tsx
@@ -0,0 +1,22 @@
+/**
+ * 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 ClassValue, clsx as cn } from 'clsx';
+import { twMerge } from 'tailwind-merge';
+
+export default function clsx(...inputs: ClassValue[]) {
+ return twMerge(cn(inputs));
+}
diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts
index ed9cbd0cd3..835d9c4531 100644
--- a/packages/design/src/index.ts
+++ b/packages/design/src/index.ts
@@ -31,7 +31,7 @@ export { FormDualColumnLayout, FormLayout, type IFormDualColumnLayoutProps, type
export { type IInputProps, type IInputWithSlotProps, Input, InputWithSlot } from './components/input';
export { type IInputNumberProps, InputNumber } from './components/input-number';
export { Menu, MenuItem, MenuItemGroup, type MenuRef, SubMenu } from './components/menu';
-export { type IMessageOptions, type IMessageProps, Message, MessageType } from './components/message';
+export { type IMessageProps, message, Messager, MessageType, removeMessage } from './components/message';
export { type IPagerProps, Pager } from './components/pager';
export { type IPopupProps, Popup } from './components/popup';
export { type IRadioProps, Radio } from './components/radio';
diff --git a/packages/docs-drawing-ui/src/global.css b/packages/docs-drawing-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/docs-drawing-ui/src/global.css
+++ b/packages/docs-drawing-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/docs-hyper-link-ui/src/global.css b/packages/docs-hyper-link-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/docs-hyper-link-ui/src/global.css
+++ b/packages/docs-hyper-link-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/docs-mention-ui/src/global.css b/packages/docs-mention-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/docs-mention-ui/src/global.css
+++ b/packages/docs-mention-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/docs-thread-comment-ui/src/global.css b/packages/docs-thread-comment-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/docs-thread-comment-ui/src/global.css
+++ b/packages/docs-thread-comment-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/docs-ui/src/global.css b/packages/docs-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/docs-ui/src/global.css
+++ b/packages/docs-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/drawing-ui/src/global.css b/packages/drawing-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/drawing-ui/src/global.css
+++ b/packages/drawing-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/find-replace/src/global.css b/packages/find-replace/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/find-replace/src/global.css
+++ b/packages/find-replace/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx b/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx
index 39be35990c..64b7233312 100644
--- a/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx
+++ b/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx
@@ -14,22 +14,22 @@
* limitations under the License.
*/
-import { Button, Checkbox, FormDualColumnLayout, FormLayout, Input, MessageType, Select } from '@univerjs/design';
-import { ILayoutService, IMessageService, useObservable } from '@univerjs/ui';
import type { IDisposable, Nullable } from '@univerjs/core';
-import { ICommandService, IContextService, LocaleService, useDependency } from '@univerjs/core';
import type { ForwardedRef } from 'react';
-import React, { forwardRef, Fragment, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
+import { ICommandService, IContextService, LocaleService, useDependency } from '@univerjs/core';
+import { Button, Checkbox, FormDualColumnLayout, FormLayout, Input, MessageType, Select } from '@univerjs/design';
+import { ILayoutService, IMessageService, useObservable } from '@univerjs/ui';
+import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
import { fromEvent } from 'rxjs';
-import { FindBy, FindDirection, FindScope, IFindReplaceService } from '../../services/find-replace.service';
-import { FIND_REPLACE_DIALOG_FOCUS, FIND_REPLACE_INPUT_FOCUS } from '../../services/context-keys';
import { ReplaceAllMatchesCommand, ReplaceCurrentMatchCommand } from '../../commands/commands/replace.command';
import { OpenReplaceDialogOperation } from '../../commands/operations/find-replace.operation';
-import { SearchInput } from './SearchInput';
-
+import { FIND_REPLACE_DIALOG_FOCUS, FIND_REPLACE_INPUT_FOCUS } from '../../services/context-keys';
+import { FindBy, FindDirection, FindScope, IFindReplaceService } from '../../services/find-replace.service';
import styles from './FindReplaceDialog.module.less';
+import { SearchInput } from './SearchInput';
+
interface ISubFormRef {
focus(): void;
selectHasFocus(): boolean;
@@ -72,7 +72,7 @@ export const FindDialog = forwardRef(function FindDialogImpl(_props, ref) {
useFindInputFocus(findReplaceService, ref);
return (
- <Fragment>
+ <>
<SearchInput
findCompleted={findCompleted}
className="univer-find-input"
@@ -88,7 +88,7 @@ export const FindDialog = forwardRef(function FindDialogImpl(_props, ref) {
{localeService.t('find-replace.dialog.advanced-finding')}
</Button>
</div>
- </Fragment>
+ </>
);
});
@@ -161,20 +161,17 @@ export const ReplaceDialog = forwardRef(function ReplaceDIalogImpl(_props, ref)
useEffect(() => {
const shouldDisplayNoMatchInfo = findCompleted && matchesCount === 0;
- let messageDisposable: Nullable<IDisposable> = null;
if (shouldDisplayNoMatchInfo) {
- messageDisposable = messageService.show({
+ messageService.show({
content: localeService.t('find-replace.dialog.no-match'),
type: MessageType.Warning,
duration: 5000,
});
}
-
- return () => messageDisposable?.dispose();
}, [findCompleted, matchesCount, messageService, localeService]);
return (
- <Fragment>
+ <>
<FormLayout label={localeService.t('find-replace.dialog.find')}>
<SearchInput
findCompleted={findCompleted}
@@ -198,17 +195,17 @@ export const ReplaceDialog = forwardRef(function ReplaceDIalogImpl(_props, ref)
<Select value={findDirection} options={findDirectionOptions} onChange={onChangeFindDirection} />
</FormLayout>
<FormDualColumnLayout>
- <Fragment>
+ <>
<FormLayout label={localeService.t('find-replace.dialog.find-scope.title')}>
<Select value={findScope} options={findScopeOptions} onChange={onChangeFindScope}></Select>
</FormLayout>
<FormLayout label={localeService.t('find-replace.dialog.find-by.title')}>
<Select value={findBy} options={findByOptions} onChange={onChangeFindBy}></Select>
</FormLayout>
- </Fragment>
+ </>
</FormDualColumnLayout>
<FormDualColumnLayout>
- <Fragment>
+ <>
<FormLayout>
<Checkbox
checked={caseSensitive}
@@ -229,7 +226,7 @@ export const ReplaceDialog = forwardRef(function ReplaceDIalogImpl(_props, ref)
{localeService.t('find-replace.dialog.match-the-whole-cell')}
</Checkbox>
</FormLayout>
- </Fragment>
+ </>
</FormDualColumnLayout>
<div className={styles.findReplaceButtonsGroup}>
<Button type="primary" onClick={onClickFindButton} disabled={findDisabled}>{localeService.t('find-replace.dialog.find')}</Button>
@@ -238,7 +235,7 @@ export const ReplaceDialog = forwardRef(function ReplaceDIalogImpl(_props, ref)
<Button disabled={replaceAllDisabled} onClick={onClickReplaceAllButton}>{localeService.t('find-replace.dialog.replace-all')}</Button>
</span>
</div>
- </Fragment>
+ </>
);
});
diff --git a/packages/sheets-conditional-formatting-ui/src/global.css b/packages/sheets-conditional-formatting-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-conditional-formatting-ui/src/global.css
+++ b/packages/sheets-conditional-formatting-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-crosshair-highlight/src/global.css b/packages/sheets-crosshair-highlight/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-crosshair-highlight/src/global.css
+++ b/packages/sheets-crosshair-highlight/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-data-validation-ui/src/global.css b/packages/sheets-data-validation-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-data-validation-ui/src/global.css
+++ b/packages/sheets-data-validation-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-drawing-ui/src/global.css b/packages/sheets-drawing-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-drawing-ui/src/global.css
+++ b/packages/sheets-drawing-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-filter-ui/src/global.css b/packages/sheets-filter-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-filter-ui/src/global.css
+++ b/packages/sheets-filter-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-formula-ui/src/global.css b/packages/sheets-formula-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-formula-ui/src/global.css
+++ b/packages/sheets-formula-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-hyper-link-ui/src/global.css b/packages/sheets-hyper-link-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-hyper-link-ui/src/global.css
+++ b/packages/sheets-hyper-link-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-numfmt-ui/src/global.css b/packages/sheets-numfmt-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-numfmt-ui/src/global.css
+++ b/packages/sheets-numfmt-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-sort-ui/src/global.css b/packages/sheets-sort-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-sort-ui/src/global.css
+++ b/packages/sheets-sort-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-thread-comment-ui/src/global.css b/packages/sheets-thread-comment-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-thread-comment-ui/src/global.css
+++ b/packages/sheets-thread-comment-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-ui/src/global.css b/packages/sheets-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-ui/src/global.css
+++ b/packages/sheets-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.ts
index 513fabef23..c1bd0e3bfe 100644
--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.ts
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.ts
@@ -15,9 +15,8 @@
*/
import type { ICellData, Injector, Nullable, Univer } from '@univerjs/core';
+import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, ThemeService } from '@univerjs/core';
-import type {
- ISetSelectionsOperationParams } from '@univerjs/sheets';
import {
AddWorksheetMergeMutation,
RemoveWorksheetMergeMutation,
@@ -28,8 +27,8 @@ import {
} from '@univerjs/sheets';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import { ISheetClipboardService } from '../clipboard.service';
import { SheetCopyCommand, SheetPasteCommand } from '../../../commands/commands/clipboard.command';
+import { ISheetClipboardService } from '../clipboard.service';
import { clipboardTestBed } from './clipboard-test-bed';
const theme = {
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.ts
index 6dabc7eef5..83a4b012f6 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
@@ -29,6 +29,8 @@ import {
IMessageService,
INotificationService,
IPlatformService,
+ IUIPartsService,
+ UIPartsService,
} from '@univerjs/ui';
import { SheetClipboardController } from '../../../controllers/clipboard/clipboard.controller';
import { IMarkSelectionService } from '../../mark-selection/mark-selection.service';
@@ -544,6 +546,7 @@ export function clipboardTestBed(workbookData?: IWorkbookData, dependencies?: De
override onStarting(): void {
const injector = this._injector;
+ injector.add([IUIPartsService, { useClass: UIPartsService }]);
injector.add([SheetsSelectionsService]);
injector.add([IClipboardInterfaceService, { useClass: BrowserClipboardService, lazy: true }]);
injector.add([ISheetClipboardService, { useClass: SheetClipboardService }]);
@@ -575,6 +578,8 @@ export function clipboardTestBed(workbookData?: IWorkbookData, dependencies?: De
const localeService = injector.get(LocaleService);
localeService.load({});
+
+ injector.get(IUIPartsService);
}
}
diff --git a/packages/sheets-zen-editor/src/global.css b/packages/sheets-zen-editor/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/sheets-zen-editor/src/global.css
+++ b/packages/sheets-zen-editor/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/slides-ui/src/global.css b/packages/slides-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/slides-ui/src/global.css
+++ b/packages/slides-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/thread-comment-ui/src/global.css b/packages/thread-comment-ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/thread-comment-ui/src/global.css
+++ b/packages/thread-comment-ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 51b8d43bd2..1c679b6ea3 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -90,7 +90,6 @@
"devDependencies": {
"@testing-library/react": "^16.0.1",
"@testing-library/react-hooks": "^8.0.1",
- "@types/react-transition-group": "^4.4.11",
"@univerjs-infra/shared": "workspace:*",
"less": "^4.2.1",
"postcss": "^8.4.49",
diff --git a/packages/ui/src/facade/f-univer.ts b/packages/ui/src/facade/f-univer.ts
index 83484d1217..5d3aa5f174 100644
--- a/packages/ui/src/facade/f-univer.ts
+++ b/packages/ui/src/facade/f-univer.ts
@@ -15,7 +15,7 @@
*/
import type { IDisposable } from '@univerjs/core';
-import type { IMessageOptions } from '@univerjs/design';
+import type { IMessageProps } from '@univerjs/design';
import type { IDialogPartMethodOptions, ISidebarMethodOptions } from '@univerjs/ui';
import type { IFacadeMenuItem, IFacadeSubmenuItem } from './f-menu-builder';
import { FUniver } from '@univerjs/core';
@@ -112,7 +112,7 @@ export interface IFUniverUIMixin {
* someAction().then(() => message.dispose());
* ```
*/
- showMessage(options: IMessageOptions): IDisposable;
+ showMessage(options: IMessageProps): void;
}
export class FUniverUIMixin extends FUniver implements IFUniverUIMixin {
@@ -164,9 +164,9 @@ export class FUniverUIMixin extends FUniver implements IFUniverUIMixin {
return this._injector.get(ComponentManager);
}
- override showMessage(options: IMessageOptions): IDisposable {
+ override showMessage(options: IMessageProps): void {
const messageService = this._injector.get(IMessageService);
- return messageService.show(options);
+ messageService.show(options);
}
}
diff --git a/packages/ui/src/global.css b/packages/ui/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/ui/src/global.css
+++ b/packages/ui/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/packages/ui/src/services/dialog/desktop-dialog.service.ts b/packages/ui/src/services/dialog/desktop-dialog.service.ts
index 5bf8565ce3..af474185de 100644
--- a/packages/ui/src/services/dialog/desktop-dialog.service.ts
+++ b/packages/ui/src/services/dialog/desktop-dialog.service.ts
@@ -14,14 +14,14 @@
* limitations under the License.
*/
+import type { IDialogPartMethodOptions } from '../../views/components/dialog-part/interface';
+import type { IDialogService } from './dialog.service';
import { connectInjector, Disposable, toDisposable } from '@univerjs/core';
+
import { type IDisposable, Inject, Injector } from '@univerjs/core';
import { Subject } from 'rxjs';
-
-import type { IDialogPartMethodOptions } from '../../views/components/dialog-part/interface';
-import { BuiltInUIPart, IUIPartsService } from '../parts/parts.service';
import { DialogPart } from '../../views/components/dialog-part/DialogPart';
-import type { IDialogService } from './dialog.service';
+import { BuiltInUIPart, IUIPartsService } from '../parts/parts.service';
export class DesktopDialogService extends Disposable implements IDialogService {
protected _dialogOptions: IDialogPartMethodOptions[] = [];
diff --git a/packages/ui/src/services/message/__testing__/mock-message.service.ts b/packages/ui/src/services/message/__testing__/mock-message.service.ts
index 9a2408e30d..07908b83b1 100644
--- a/packages/ui/src/services/message/__testing__/mock-message.service.ts
+++ b/packages/ui/src/services/message/__testing__/mock-message.service.ts
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-import type { IMessageOptions, IMessageProps } from '@univerjs/design';
import type { IDisposable } from '@univerjs/core';
+import type { IMessageProps } from '@univerjs/design';
-import { toDisposable } from '@univerjs/core';
import type { IMessageService } from '../message.service';
+import { toDisposable } from '@univerjs/core';
/**
* This is a mocked message service for testing purposes.
*/
export class MockMessageService implements IMessageService {
- show(_options: IMessageOptions & Omit<IMessageProps, 'key'>): IDisposable {
+ show(_options: IMessageProps): IDisposable {
return toDisposable(() => { /* empty */ });
}
diff --git a/packages/ui/src/services/message/desktop-message.service.ts b/packages/ui/src/services/message/desktop-message.service.ts
index 1206f826ba..665370cad0 100644
--- a/packages/ui/src/services/message/desktop-message.service.ts
+++ b/packages/ui/src/services/message/desktop-message.service.ts
@@ -14,45 +14,34 @@
* limitations under the License.
*/
-import type { IDisposable } from '@univerjs/core';
-import type { IMessageOptions, IMessageProps } from '@univerjs/design';
+import type { IMessageProps } from '@univerjs/design';
import type { IMessageService } from './message.service';
+import { connectInjector, Disposable, Inject, Injector } from '@univerjs/core';
+import { message, Messager, removeMessage } from '@univerjs/design';
-import { Message } from '@univerjs/design';
-import canUseDom from 'rc-util/lib/Dom/canUseDom';
+import { BuiltInUIPart, IUIPartsService } from '../parts/parts.service';
-export class DesktopMessageService implements IMessageService, IDisposable {
- // in node environment, document is undefined
- protected _portalContainer: HTMLElement | undefined = canUseDom() ? document.body : undefined;
+export class DesktopMessageService extends Disposable implements IMessageService {
+ constructor(
+ @Inject(Injector) protected readonly _injector: Injector,
+ @IUIPartsService protected readonly _uiPartsService: IUIPartsService
+ ) {
+ super();
- protected _message?: Message;
-
- dispose(): void {
- this._message?.dispose();
+ this._initUIPart();
}
- setContainer(container: HTMLElement): void {
- if (this._message) {
- return;
- }
-
- this._portalContainer = container;
- this._message = new Message(container);
+ protected _initUIPart(): void {
+ this.disposeWithMe(
+ this._uiPartsService.registerComponent(BuiltInUIPart.GLOBAL, () => connectInjector(Messager, this._injector))
+ );
}
- getContainer(): HTMLElement | undefined {
- return this._portalContainer;
+ override dispose(): void {
+ removeMessage();
}
- show(options: IMessageOptions & Omit<IMessageProps, 'key'>): IDisposable {
- if (!this._portalContainer) {
- throw new Error('[DesktopMessageService]: no container to show message!');
- }
- if (!this._message) {
- throw new Error('[DesktopMessageService]: no message implementation!');
- }
-
- const { type, ...rest } = options;
- return this._message[type](rest);
+ show(options: IMessageProps) {
+ message(options);
}
}
diff --git a/packages/ui/src/services/message/message.service.ts b/packages/ui/src/services/message/message.service.ts
index cb7b32b906..9662763d53 100644
--- a/packages/ui/src/services/message/message.service.ts
+++ b/packages/ui/src/services/message/message.service.ts
@@ -14,15 +14,11 @@
* limitations under the License.
*/
-import type { IDisposable } from '@univerjs/core';
-import type { IMessageOptions } from '@univerjs/design';
+import type { IMessageProps } from '@univerjs/design';
import { createIdentifier } from '@univerjs/core';
export const IMessageService = createIdentifier<IMessageService>('ui.message.service');
export interface IMessageService {
- show(options: IMessageOptions): IDisposable;
-
- setContainer(container: HTMLElement): void;
- getContainer(): HTMLElement | undefined;
+ show(options: IMessageProps): void;
}
diff --git a/packages/ui/src/views/MobileApp.tsx b/packages/ui/src/views/MobileApp.tsx
index e7e59e5362..3554e45fad 100644
--- a/packages/ui/src/views/MobileApp.tsx
+++ b/packages/ui/src/views/MobileApp.tsx
@@ -19,7 +19,6 @@ import type { IWorkbenchOptions } from '../controllers/ui/ui.controller';
import { LocaleService, ThemeService, useDependency } from '@univerjs/core';
import { ConfigProvider, defaultTheme, themeInstance } from '@univerjs/design';
import React, { useEffect, useMemo, useRef, useState } from 'react';
-import { IMessageService } from '../services/message/message.service';
import { BuiltInUIPart } from '../services/parts/parts.service';
import { ComponentContainer, useComponentsOfPart } from './components/ComponentContainer';
import { MobileContextMenu } from './components/context-menu/MobileContextMenu';
@@ -45,12 +44,10 @@ export function MobileApp(props: IUniverAppProps) {
const localeService = useDependency(LocaleService);
const themeService = useDependency(ThemeService);
- const messageService = useDependency(IMessageService);
const contentRef = useRef<HTMLDivElement>(null);
const footerComponents = useComponentsOfPart(BuiltInUIPart.FOOTER);
const headerComponents = useComponentsOfPart(BuiltInUIPart.HEADER);
- const headerMenuComponents = useComponentsOfPart(BuiltInUIPart.HEADER_MENU);
const contentComponents = useComponentsOfPart(BuiltInUIPart.CONTENT);
const leftSidebarComponents = useComponentsOfPart(BuiltInUIPart.LEFT_SIDEBAR);
const globalComponents = useComponentsOfPart(BuiltInUIPart.GLOBAL);
@@ -75,7 +72,6 @@ export function MobileApp(props: IUniverAppProps) {
useEffect(() => {
document.body.appendChild(portalContainer);
- messageService.setContainer(portalContainer);
const subscriptions = [
localeService.localeChanged$.subscribe(() => {
@@ -94,7 +90,7 @@ export function MobileApp(props: IUniverAppProps) {
// cleanup
document.body.removeChild(portalContainer);
};
- }, [localeService, messageService, mountContainer, portalContainer, themeService.currentTheme$]);
+ }, [localeService, mountContainer, portalContainer, themeService.currentTheme$]);
return (
<ConfigProvider locale={locale?.design} mountContainer={portalContainer}>
diff --git a/packages/ui/src/views/components/global-zone/GlobalZone.tsx b/packages/ui/src/views/components/global-zone/GlobalZone.tsx
index 4f818309c5..146c5a3686 100644
--- a/packages/ui/src/views/components/global-zone/GlobalZone.tsx
+++ b/packages/ui/src/views/components/global-zone/GlobalZone.tsx
@@ -18,8 +18,8 @@ import { useDependency } from '@univerjs/core';
import clsx from 'clsx';
import React, { useEffect, useMemo, useState } from 'react';
import { ComponentManager } from '../../../common/component-manager';
-import { IGlobalZoneService } from '../../../services/global-zone/global-zone.service';
import { useObservable } from '../../../components/hooks/observable';
+import { IGlobalZoneService } from '../../../services/global-zone/global-zone.service';
import styles from './index.module.less';
diff --git a/packages/ui/src/views/workbench/Workbench.tsx b/packages/ui/src/views/workbench/Workbench.tsx
index fe6bae5001..165dc429d2 100644
--- a/packages/ui/src/views/workbench/Workbench.tsx
+++ b/packages/ui/src/views/workbench/Workbench.tsx
@@ -17,20 +17,18 @@
import type { DocumentDataModel, IDocumentData, Nullable } from '@univerjs/core';
import type { ILocale } from '@univerjs/design';
import type { IWorkbenchOptions } from '../../controllers/ui/ui.controller';
-import { DocumentFlavor, IUniverInstanceService, LocaleService, ThemeService, UniverInstanceType, useDependency, useObservable } from '@univerjs/core';
+import { DocumentFlavor, IUniverInstanceService, LocaleService, ThemeService, UniverInstanceType, useDependency } from '@univerjs/core';
import { ConfigContext, ConfigProvider, defaultTheme, themeInstance } from '@univerjs/design';
import clsx from 'clsx';
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
-import { IMessageService } from '../../services/message/message.service';
import { BuiltInUIPart } from '../../services/parts/parts.service';
-import { IZenZoneService } from '../../services/zen-zone/zen-zone.service';
import { ComponentContainer, useComponentsOfPart } from '../components/ComponentContainer';
import { DesktopContextMenu } from '../components/context-menu/ContextMenu';
import { Ribbon } from '../components/ribbon/Ribbon';
-import { Sidebar } from '../components/sidebar/Sidebar';
+import { Sidebar } from '../components/sidebar/Sidebar';
import { ZenZone } from '../components/zen-zone/ZenZone';
import { builtInGlobalComponents } from '../parts';
import styles from './workbench.module.less';
@@ -53,7 +51,6 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
const localeService = useDependency(LocaleService);
const themeService = useDependency(ThemeService);
- const messageService = useDependency(IMessageService);
const instanceService = useDependency(IUniverInstanceService);
const contentRef = useRef<HTMLDivElement>(null);
@@ -64,8 +61,6 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
const contentComponents = useComponentsOfPart(BuiltInUIPart.CONTENT);
const leftSidebarComponents = useComponentsOfPart(BuiltInUIPart.LEFT_SIDEBAR);
const globalComponents = useComponentsOfPart(BuiltInUIPart.GLOBAL);
- const zenService = useDependency(IZenZoneService);
- const zenZoneVisible = useObservable(zenService.visible$, zenService.visible);
const [docSnapShot, setDocSnapShot] = useState<Nullable<IDocumentData>>(null);
@@ -108,7 +103,6 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
useEffect(() => {
document.body.appendChild(portalContainer);
- messageService.setContainer(portalContainer);
const subscriptions = [
localeService.localeChanged$.subscribe(() => {
@@ -129,7 +123,7 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
// cleanup
document.body.removeChild(portalContainer);
};
- }, [localeService, messageService, mountContainer, portalContainer, themeService.currentTheme$]);
+ }, [localeService, mountContainer, portalContainer, themeService.currentTheme$]);
return (
<ConfigProvider locale={locale?.design} mountContainer={portalContainer}>
@@ -199,7 +193,6 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
<ComponentContainer key="built-in-global" components={builtInGlobalComponents} />
{contextMenu && <DesktopContextMenu />}
<FloatingContainer />
-
</ConfigProvider>
);
}
diff --git a/packages/uniscript/src/global.css b/packages/uniscript/src/global.css
index 7c05d4ddc4..b5c61c9567 100644
--- a/packages/uniscript/src/global.css
+++ b/packages/uniscript/src/global.css
@@ -1,2 +1,3 @@
+@tailwind base;
@tailwind components;
@tailwind utilities;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b96a05487f..d1e89ccba1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -49,7 +49,7 @@ importers:
version: link:packages/design
'@vitejs/plugin-react':
specifier: ^4.3.4
eslint:
specifier: 9.16.0
version: 9.16.0([email protected])
@@ -137,6 +137,9 @@ importers:
tailwindcss:
specifier: ^3.4.16
version: 3.4.16
+ tailwindcss-animate:
+ specifier: ^1.0.7
+ version: 1.0.7([email protected])
vite:
specifier: ^6.0.3
@@ -1209,6 +1212,9 @@ importers:
react-transition-group:
specifier: ^4.4.5
+ tailwind-merge:
+ specifier: ^2.5.5
+ version: 2.5.5
devDependencies:
'@testing-library/react':
specifier: ^16.0.1
@@ -1218,7 +1224,7 @@ importers:
version: 1.3.5
'@types/react-transition-group':
specifier: ^4.4.11
- version: 4.4.11
+ version: 4.4.12(@types/[email protected])
'@univerjs-infra/shared':
specifier: workspace:*
version: link:../../common/shared
@@ -3337,9 +3343,6 @@ importers:
'@testing-library/react-hooks':
specifier: ^8.0.1
- '@types/react-transition-group':
- specifier: ^4.4.11
- version: 4.4.11
'@univerjs-infra/shared':
specifier: workspace:*
version: link:../../common/shared
@@ -5199,8 +5202,10 @@ packages:
resolution: {integrity: sha512-dKnY1h42GPUO/QAyei6HxEsFUbEcqK/t1k60ZbLJstB9RAs8OCT69mj9AnUbeNdbzYVISE88OC2IYkkthAAn2g==}
- '@types/[email protected]':
- resolution: {integrity: sha512-RM05tAniPZ5DZPzzNFP+DmrcOdD0efDUxMy3145oljWSl3x9ZV5vhme98gTxFrj2lhXvmGNnUiuDyJgY9IKkNA==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-8TV6R3h2j7a91c+1DXdJi3Syo69zzIZbz7Lg5tORM5LEJG7X/E6a1V3drRyBRZq7/utz7A+c4OgYLiLcYGHG6w==}
+ peerDependencies:
+ '@types/react': '*'
resolution: {integrity: sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw==}
@@ -9896,6 +9901,14 @@ packages:
resolution: {integrity: sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==}
engines: {node: ^14.18.0 || >=16.0.0}
+ resolution: {integrity: sha512-0LXunzzAZzo0tEPxV3I297ffKZPlKDrjj7NXphC8V5ak9yHC5zRmxnOe2m/Rd/7ivsOMJe3JZ2JVocoDdQTRBA==}
+
+ resolution: {integrity: sha512-bl6mpH3T7I3UFxuvDEXLxy/VuFxBk5bbzplh7tXI68mwMokNYd1t9qPBHlnyTwfa4JGC4zP516I1hYYtQ/vspA==}
+ peerDependencies:
+ tailwindcss: '>=3.0.0 || insiders'
+
resolution: {integrity: sha512-TI4Cyx7gDiZ6r44ewaJmt0o6BrMCT5aK5e0rmJ/G9Xq3w7CX/5VXl/zIPEJZFUK5VEqwByyhqNPycPlvcK4ZNw==}
engines: {node: '>=14.0.0'}
@@ -12385,7 +12398,7 @@ snapshots:
dependencies:
'@types/react': 18.3.12
- '@types/[email protected]':
dependencies:
'@types/react': 18.3.12
@@ -12511,17 +12524,6 @@ snapshots:
'@grpc/grpc-js': 1.10.9
rxjs: 7.8.1
- dependencies:
- '@babel/core': 7.26.0
- '@babel/plugin-transform-react-jsx-self': 7.25.9(@babel/[email protected])
- '@babel/plugin-transform-react-jsx-source': 7.25.9(@babel/[email protected])
- '@types/babel__core': 7.20.5
- react-refresh: 0.14.2
- transitivePeerDependencies:
- - supports-color
-
dependencies:
'@babel/core': 7.26.0
@@ -13801,7 +13803,7 @@ snapshots:
dependencies:
- '@babel/runtime': 7.24.7
+ '@babel/runtime': 7.26.0
csstype: 3.1.3
@@ -17161,7 +17163,7 @@ snapshots:
dependencies:
- '@babel/runtime': 7.24.7
+ '@babel/runtime': 7.26.0
dom-helpers: 5.2.1
loose-envify: 1.4.0
prop-types: 15.8.1
@@ -17840,6 +17842,12 @@ snapshots:
'@pkgr/core': 0.1.1
tslib: 2.8.1
+
+ dependencies:
+ tailwindcss: 3.4.16
+
dependencies:
'@alloc/quick-lru': 5.2.0