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.

feat(base-ui): support IDialogService & IConfirmService (#379)

白熱9de889eb0885
diff --git a/packages/base-ui/src/base-ui-plugin.ts b/packages/base-ui/src/base-ui-plugin.ts
index bb1f580f36..33c687cff7 100644
--- a/packages/base-ui/src/base-ui-plugin.ts
+++ b/packages/base-ui/src/base-ui-plugin.ts
@@ -9,7 +9,11 @@ import { IUIController, IWorkbenchOptions } from './controllers/ui/ui.controller
import { DesktopUIController } from './controllers/ui/ui-desktop.controller';
import { enUS } from './locale';
import { BrowserClipboardService, IClipboardInterfaceService } from './services/clipboard/clipboard-interface.service';
+import { IConfirmService } from './services/confirm/confirm.service';
+import { DesktopConfirmService } from './services/confirm/desktop-confirm.service';
import { DesktopContextMenuService, IContextMenuService } from './services/contextmenu/contextmenu.service';
+import { DesktopDialogService } from './services/dialog/desktop-dialog.service';
+import { IDialogService } from './services/dialog/dialog.service';
import { DesktopFocusService, IFocusService } from './services/focus/focus.service';
import { DesktopLocalStorageService } from './services/local-storage/local-storage.service';
import { DesktopMenuService, IMenuService } from './services/menu/menu.service';
@@ -68,6 +72,8 @@ export class UIPlugin extends Plugin {
[IContextMenuService, { useClass: DesktopContextMenuService }],
[IClipboardInterfaceService, { useClass: BrowserClipboardService, lazy: true }],
[INotificationService, { useClass: DesktopNotificationService, lazy: true }],
+ [IDialogService, { useClass: DesktopDialogService, lazy: true }],
+ [IConfirmService, { useClass: DesktopConfirmService, lazy: true }],
[IMessageService, { useClass: DesktopMessageService, lazy: true }],
[ILocalStorageService, { useClass: DesktopLocalStorageService, lazy: true }],
// controllers
diff --git a/packages/base-ui/src/components/custom-label/CustomLabel.tsx b/packages/base-ui/src/components/custom-label/CustomLabel.tsx
index aefd12fc53..363309b279 100644
--- a/packages/base-ui/src/components/custom-label/CustomLabel.tsx
+++ b/packages/base-ui/src/components/custom-label/CustomLabel.tsx
@@ -4,28 +4,21 @@ import { useDependency } from '@wendellhu/redi/react-bindings';
import { ComponentManager } from '../../Common';
import { IMenuSelectorItem } from '../../services/menu/menu';
-import styles from './index.module.less';
-export interface ICustomLabelProps {
+export type ICustomLabelProps = {
value?: string | number | undefined;
selected?: boolean;
- /**
- * Triggered after value change
- */
onChange?(v: string | number): void;
-}
+} & Pick<IMenuSelectorItem<unknown>, 'label' | 'icon' | 'title'>;
/**
* The component to render toolbar item label and menu item label.
* @param props
* @returns
- * @deprecated
*/
-export function CustomLabel(
- props: Pick<IMenuSelectorItem<unknown>, 'label' | 'icon' | 'title'> & ICustomLabelProps
-): JSX.Element | null {
+export function CustomLabel(props: ICustomLabelProps): JSX.Element | null {
const { title, icon, label, selected } = props;
const localeService = useDependency(LocaleService);
const componentManager = useDependency(ComponentManager);
@@ -56,5 +49,5 @@ export function CustomLabel(
nodes.push(<span key={index++}>{localeService.t(title)}</span>);
}
- return <span className={styles.customLabel}>{nodes}</span>;
+ return <>{nodes}</>;
}
diff --git a/packages/base-ui/src/components/custom-label/index.module.less b/packages/base-ui/src/components/custom-label/index.module.less
deleted file mode 100644
index a802a5c669..0000000000
--- a/packages/base-ui/src/components/custom-label/index.module.less
+++ /dev/null
@@ -1,5 +0,0 @@
-.custom-label {
- display: inline-flex;
- align-items: center;
- gap: var(--margin-xs);
-}
diff --git a/packages/base-ui/src/components/menu/Menu.tsx b/packages/base-ui/src/components/menu/Menu.tsx
index bb1751d1d9..d9f47b6bd2 100644
--- a/packages/base-ui/src/components/menu/Menu.tsx
+++ b/packages/base-ui/src/components/menu/Menu.tsx
@@ -97,13 +97,15 @@ function MenuOptionsWrapper(props: IBaseMenuProps) {
});
}}
>
- <CustomLabel
- selected={String(value) === String(option.value)} // use √ for select
- value={String(option.value)}
- label={option.label}
- title={typeof option.label === 'string' ? option.label : ''}
- icon={option.icon}
- />
+ <span className={styles.menuItemContent}>
+ <CustomLabel
+ selected={String(value) === String(option.value)} // use √ for select
+ value={String(option.value)}
+ label={option.label}
+ title={typeof option.label === 'string' ? option.label : ''}
+ icon={option.icon}
+ />
+ </span>
</RcMenuItem>
);
}
@@ -204,7 +206,7 @@ function MenuItem({ menuItem, onClick }: IMenuItemProps) {
className={clsx(styles.menuItem, disabled ? styles.menuItemDisabled : '')}
popupOffset={[18, 0]}
title={
- <>
+ <span className={styles.menuItemContent}>
<CustomLabel
title={item.title}
value={inputValue}
@@ -213,7 +215,7 @@ function MenuItem({ menuItem, onClick }: IMenuItemProps) {
label={item.label}
/>
{item.shortcut && ` (${item.shortcut})`}
- </>
+ </span>
}
expandIcon={<MoreSingle className={styles.menuItemMoreIcon} />}
>
@@ -237,14 +239,16 @@ function MenuItem({ menuItem, onClick }: IMenuItemProps) {
eventKey={item.id}
className={clsx(styles.menuItem, disabled ? styles.menuItemDisabled : '')}
>
- <CustomLabel
- title={item.title}
- value={inputValue}
- onChange={onChange}
- icon={item.icon}
- label={item.label}
- />
- {item.shortcut && ` (${item.shortcut})`}
+ <span className={styles.menuItemContent}>
+ <CustomLabel
+ title={item.title}
+ value={inputValue}
+ onChange={onChange}
+ icon={item.icon}
+ label={item.label}
+ />
+ {item.shortcut && ` (${item.shortcut})`}
+ </span>
</RcMenuItem>
);
};
@@ -259,9 +263,9 @@ function MenuItem({ menuItem, onClick }: IMenuItemProps) {
className={clsx(styles.menuItem, disabled ? styles.menuItemDisabled : '')}
popupOffset={[18, 0]}
title={
- <>
+ <span className={styles.menuItemContent}>
<CustomLabel title={item.title} value={item.title} icon={item.icon} label={item.label} />
- </>
+ </span>
}
expandIcon={<MoreSingle className={styles.menuItemMoreIcon} />}
>
diff --git a/packages/base-ui/src/components/menu/index.module.less b/packages/base-ui/src/components/menu/index.module.less
index a0603b4271..3cb09211a3 100644
--- a/packages/base-ui/src/components/menu/index.module.less
+++ b/packages/base-ui/src/components/menu/index.module.less
@@ -63,6 +63,14 @@
margin-top: 0;
}
+ &-item {
+ &-content {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--margin-xs);
+ }
+ }
+
&-item,
&-submenu-title {
margin: 0;
diff --git a/packages/base-ui/src/components/notification/Notification.tsx b/packages/base-ui/src/components/notification/Notification.tsx
index 2f5440bf8f..028c221a55 100644
--- a/packages/base-ui/src/components/notification/Notification.tsx
+++ b/packages/base-ui/src/components/notification/Notification.tsx
@@ -146,8 +146,6 @@ class NotificationInstance {
const instance = new NotificationInstance();
-const notification = {
+export const notification = {
show: (options: INotificationMethodOptions) => instance.show(options),
};
-
-export { notification };
diff --git a/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx b/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
index ac4b52c1b5..293573f03a 100644
--- a/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
+++ b/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
@@ -7,7 +7,7 @@ import { createRoot } from 'react-dom/client';
import { Observable, Subject } from 'rxjs';
import { IFocusService } from '../../services/focus/focus.service';
-import { App } from '../../views/app';
+import { App } from '../../views/App';
import { IUIController, IWorkbenchOptions } from './ui.controller';
export enum DesktopUIPart {
diff --git a/packages/base-ui/src/index.ts b/packages/base-ui/src/index.ts
index 61dc06a02f..c415097b3f 100644
--- a/packages/base-ui/src/index.ts
+++ b/packages/base-ui/src/index.ts
@@ -15,11 +15,15 @@ export {
IClipboardInterfaceService,
PLAIN_TEXT_CLIPBOARD_MIME_TYPE,
} from './services/clipboard/clipboard-interface.service';
+export { IConfirmService } from './services/confirm/confirm.service';
+export { DesktopConfirmService } from './services/confirm/desktop-confirm.service';
export {
DesktopContextMenuService,
type IContextMenuHandler,
IContextMenuService,
} from './services/contextmenu/contextmenu.service';
+export { DesktopDialogService } from './services/dialog/desktop-dialog.service';
+export { IDialogService } from './services/dialog/dialog.service';
export {
type ICustomComponentOption,
type ICustomComponentProps,
diff --git a/packages/base-ui/src/services/confirm/confirm.service.ts b/packages/base-ui/src/services/confirm/confirm.service.ts
new file mode 100644
index 0000000000..f4f3bf7f18
--- /dev/null
+++ b/packages/base-ui/src/services/confirm/confirm.service.ts
@@ -0,0 +1,14 @@
+import { createIdentifier, IDisposable } from '@wendellhu/redi';
+import { type Subject } from 'rxjs';
+
+import { type IConfirmPartMethodOptions } from '../../views/components/confirm-part/interface';
+
+export const IConfirmService = createIdentifier<IConfirmService>('univer.confirm-service');
+
+export interface IConfirmService {
+ open(params: IConfirmPartMethodOptions): IDisposable;
+
+ close(id: string): void;
+
+ getObservableConfirm(): Subject<IConfirmPartMethodOptions[]>;
+}
diff --git a/packages/base-ui/src/services/confirm/desktop-confirm.service.ts b/packages/base-ui/src/services/confirm/desktop-confirm.service.ts
new file mode 100644
index 0000000000..00d8602900
--- /dev/null
+++ b/packages/base-ui/src/services/confirm/desktop-confirm.service.ts
@@ -0,0 +1,43 @@
+import { toDisposable } from '@univerjs/core';
+import { IDisposable } from '@wendellhu/redi';
+import { Subject } from 'rxjs';
+
+import { type IConfirmPartMethodOptions } from '../../views/components/confirm-part/interface';
+import { IConfirmService } from './confirm.service';
+
+export class DesktopConfirmService implements IConfirmService {
+ private confirmOptions: IConfirmPartMethodOptions[] = [];
+ private readonly confirmOptions$ = new Subject<IConfirmPartMethodOptions[]>();
+
+ open(option: IConfirmPartMethodOptions): IDisposable {
+ if (this.confirmOptions.find((item) => item.id === option.id)) {
+ this.confirmOptions = this.confirmOptions.map((item) => ({
+ ...(item.id === option.id ? option : item),
+ visible: true,
+ }));
+ } else {
+ this.confirmOptions.push({
+ ...option,
+ visible: true,
+ });
+ }
+ this.confirmOptions$.next(this.confirmOptions);
+
+ return toDisposable(() => {
+ this.confirmOptions = [];
+ this.confirmOptions$.next([]);
+ });
+ }
+
+ close(id: string): void {
+ this.confirmOptions = this.confirmOptions.map((item) => ({
+ ...item,
+ visible: item.id === id ? false : item.visible,
+ }));
+ this.confirmOptions$.next([...this.confirmOptions]);
+ }
+
+ getObservableConfirm() {
+ return this.confirmOptions$;
+ }
+}
diff --git a/packages/base-ui/src/services/dialog/desktop-dialog.service.ts b/packages/base-ui/src/services/dialog/desktop-dialog.service.ts
new file mode 100644
index 0000000000..dce8babdcc
--- /dev/null
+++ b/packages/base-ui/src/services/dialog/desktop-dialog.service.ts
@@ -0,0 +1,44 @@
+import { toDisposable } from '@univerjs/core';
+import { IDisposable } from '@wendellhu/redi';
+import { Subject } from 'rxjs';
+
+import { type IDialogPartMethodOptions } from '../../views/components/dialog-part/interface';
+import { IDialogService } from './dialog.service';
+
+export class DesktopDialogService implements IDialogService {
+ private dialogOptions: IDialogPartMethodOptions[] = [];
+ private readonly dialogOptions$ = new Subject<IDialogPartMethodOptions[]>();
+
+ open(option: IDialogPartMethodOptions): IDisposable {
+ if (this.dialogOptions.find((item) => item.id === option.id)) {
+ this.dialogOptions = this.dialogOptions.map((item) => ({
+ ...(item.id === option.id ? option : item),
+ visible: true,
+ }));
+ } else {
+ this.dialogOptions.push({
+ ...option,
+ visible: true,
+ });
+ }
+
+ this.dialogOptions$.next(this.dialogOptions);
+
+ return toDisposable(() => {
+ this.dialogOptions = [];
+ this.dialogOptions$.next([]);
+ });
+ }
+
+ close(id: string) {
+ this.dialogOptions = this.dialogOptions.map((item) => ({
+ ...item,
+ visible: item.id === id ? false : item.visible,
+ }));
+ this.dialogOptions$.next([...this.dialogOptions]);
+ }
+
+ getObservableDialog() {
+ return this.dialogOptions$;
+ }
+}
diff --git a/packages/base-ui/src/services/dialog/dialog.service.ts b/packages/base-ui/src/services/dialog/dialog.service.ts
new file mode 100644
index 0000000000..158a6aa009
--- /dev/null
+++ b/packages/base-ui/src/services/dialog/dialog.service.ts
@@ -0,0 +1,14 @@
+import { createIdentifier, IDisposable } from '@wendellhu/redi';
+import { type Subject } from 'rxjs';
+
+import { type IDialogPartMethodOptions } from '../../views/components/dialog-part/interface';
+
+export const IDialogService = createIdentifier<IDialogService>('univer.dialog-service');
+
+export interface IDialogService {
+ open(params: IDialogPartMethodOptions): IDisposable;
+
+ close(id: string): void;
+
+ getObservableDialog(): Subject<IDialogPartMethodOptions[]>;
+}
diff --git a/packages/base-ui/src/services/menu/menu.service.ts b/packages/base-ui/src/services/menu/menu.service.ts
index 0e59d5ea5d..166c0e3527 100644
--- a/packages/base-ui/src/services/menu/menu.service.ts
+++ b/packages/base-ui/src/services/menu/menu.service.ts
@@ -51,6 +51,7 @@ export class DesktopMenuService extends Disposable implements IMenuService {
this._menuChanged$.next();
return toDisposable(() => {
+ console.log(item.id);
this._menuItemMap.delete(item.id);
if (Array.isArray(item.positions)) {
diff --git a/packages/base-ui/src/views/app.tsx b/packages/base-ui/src/views/App.tsx
similarity index 96%
rename from packages/base-ui/src/views/app.tsx
rename to packages/base-ui/src/views/App.tsx
index 35a9a1801e..7bd9c70970 100644
--- a/packages/base-ui/src/views/app.tsx
+++ b/packages/base-ui/src/views/App.tsx
@@ -16,8 +16,9 @@ import React, { ComponentType, useEffect, useRef, useState } from 'react';
import { IWorkbenchOptions } from '../controllers/ui/ui.controller';
import style from './app.module.less';
-import { ContextMenu } from './components/ContextMenu';
-import { DocBars } from './components/DocBars';
+import { ContextMenu } from './components/context-menu/ContextMenu';
+import { DocBars } from './components/doc-bars/DocBars';
+import { Parts } from './Parts';
export interface IUniverAppProps extends IWorkbenchOptions {
headerComponents?: Set<() => ComponentType>;
@@ -128,6 +129,7 @@ export function App(props: IUniverAppProps) {
</Layout>
</Layout>
</Container>
+ <Parts />
</ConfigProvider>
);
}
diff --git a/packages/base-ui/src/views/Parts.tsx b/packages/base-ui/src/views/Parts.tsx
new file mode 100644
index 0000000000..3b09f208b1
--- /dev/null
+++ b/packages/base-ui/src/views/Parts.tsx
@@ -0,0 +1,11 @@
+import { ConfirmPart } from './components/confirm-part/ConfirmPart';
+import { DialogPart } from './components/dialog-part/DialogPart';
+
+export function Parts() {
+ return (
+ <>
+ <DialogPart />
+ <ConfirmPart />
+ </>
+ );
+}
diff --git a/packages/base-ui/src/views/components/ContextMenu/index.ts b/packages/base-ui/src/views/components/ContextMenu/index.ts
deleted file mode 100644
index b1e8a57afa..0000000000
--- a/packages/base-ui/src/views/components/ContextMenu/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { ContextMenu } from './ContextMenu';
diff --git a/packages/base-ui/src/views/components/DocBars/index.ts b/packages/base-ui/src/views/components/DocBars/index.ts
deleted file mode 100644
index c72b111504..0000000000
--- a/packages/base-ui/src/views/components/DocBars/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { DocBars } from './DocBars';
diff --git a/packages/base-ui/src/views/components/confirm-part/ConfirmPart.tsx b/packages/base-ui/src/views/components/confirm-part/ConfirmPart.tsx
new file mode 100644
index 0000000000..29ad03584b
--- /dev/null
+++ b/packages/base-ui/src/views/components/confirm-part/ConfirmPart.tsx
@@ -0,0 +1,42 @@
+import { Confirm, IConfirmProps } from '@univerjs/design';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { useEffect, useState } from 'react';
+
+import { CustomLabel } from '../../../components/custom-label/CustomLabel';
+import { IConfirmService } from '../../../services/confirm/confirm.service';
+import { IConfirmPartMethodOptions } from './interface';
+
+export function ConfirmPart() {
+ const confirmService = useDependency(IConfirmService);
+
+ const [confirmOptions, setConfirmOptions] = useState<IConfirmPartMethodOptions[]>([]);
+
+ useEffect(() => {
+ const confirm$ = confirmService.getObservableConfirm();
+ const subscribtion = confirm$.subscribe((options: IConfirmPartMethodOptions[]) => {
+ setConfirmOptions(options);
+ });
+
+ return () => {
+ subscribtion.unsubscribe();
+ };
+ }, []);
+
+ const props = confirmOptions.map((options) => {
+ const { children, title, ...restProps } = options;
+
+ const confirmProps = restProps as IConfirmProps & { id: string };
+ for (const key of ['children', 'title']) {
+ const k = key as keyof IConfirmPartMethodOptions;
+ const props = options[k] as any;
+
+ if (props) {
+ (confirmProps as any)[k] = <CustomLabel {...props} />;
+ }
+ }
+
+ return confirmProps;
+ });
+
+ return props?.map((options, index) => <Confirm key={index} {...options} />);
+}
diff --git a/packages/base-ui/src/views/components/confirm-part/interface.ts b/packages/base-ui/src/views/components/confirm-part/interface.ts
new file mode 100644
index 0000000000..511b2d9da5
--- /dev/null
+++ b/packages/base-ui/src/views/components/confirm-part/interface.ts
@@ -0,0 +1,9 @@
+import { IConfirmProps } from '@univerjs/design';
+
+import { type ICustomLabelProps } from '../../../components/custom-label/CustomLabel';
+
+export type IConfirmPartMethodOptions = {
+ id: string;
+ children?: ICustomLabelProps;
+ title?: ICustomLabelProps;
+} & Omit<IConfirmProps, 'children' | 'title'>;
diff --git a/packages/base-ui/src/views/components/ContextMenu/ContextMenu.tsx b/packages/base-ui/src/views/components/context-menu/ContextMenu.tsx
similarity index 100%
rename from packages/base-ui/src/views/components/ContextMenu/ContextMenu.tsx
rename to packages/base-ui/src/views/components/context-menu/ContextMenu.tsx
diff --git a/packages/base-ui/src/views/components/dialog-part/DialogPart.tsx b/packages/base-ui/src/views/components/dialog-part/DialogPart.tsx
new file mode 100644
index 0000000000..8d8ed51f19
--- /dev/null
+++ b/packages/base-ui/src/views/components/dialog-part/DialogPart.tsx
@@ -0,0 +1,42 @@
+import { Dialog, IDialogProps } from '@univerjs/design';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { useEffect, useState } from 'react';
+
+import { CustomLabel } from '../../../components/custom-label/CustomLabel';
+import { IDialogService } from '../../../services/dialog/dialog.service';
+import { IDialogPartMethodOptions } from './interface';
+
+export function DialogPart() {
+ const dialogService = useDependency(IDialogService);
+
+ const [dialogOptions, setDialogOptions] = useState<IDialogPartMethodOptions[]>([]);
+
+ useEffect(() => {
+ const dialog$ = dialogService.getObservableDialog();
+ const subscribtion = dialog$.subscribe((options: IDialogPartMethodOptions[]) => {
+ setDialogOptions(options);
+ });
+
+ return () => {
+ subscribtion.unsubscribe();
+ };
+ }, []);
+
+ const props = dialogOptions.map((options) => {
+ const { children, title, closeIcon, footer, ...restProps } = options;
+
+ const dialogProps = restProps as IDialogProps & { id: string };
+ for (const key of ['children', 'title', 'closeIcon', 'footer']) {
+ const k = key as keyof IDialogPartMethodOptions;
+ const props = options[k] as any;
+
+ if (props) {
+ (dialogProps as any)[k] = <CustomLabel {...props} />;
+ }
+ }
+
+ return dialogProps;
+ });
+
+ return <>{props?.map((options) => <Dialog key={options.id} {...options} />)}</>;
+}
diff --git a/packages/base-ui/src/views/components/dialog-part/interface.ts b/packages/base-ui/src/views/components/dialog-part/interface.ts
new file mode 100644
index 0000000000..0f948f7c1b
--- /dev/null
+++ b/packages/base-ui/src/views/components/dialog-part/interface.ts
@@ -0,0 +1,11 @@
+import { IDialogProps } from '@univerjs/design';
+
+import { type ICustomLabelProps } from '../../../components/custom-label/CustomLabel';
+
+export type IDialogPartMethodOptions = {
+ id: string;
+ children?: ICustomLabelProps;
+ title?: ICustomLabelProps;
+ closeIcon?: ICustomLabelProps;
+ footer?: ICustomLabelProps;
+} & Omit<IDialogProps, 'children' | 'title' | 'closeIcon' | 'footer'>;
diff --git a/packages/base-ui/src/views/components/DocBars/Button/ToolbarButton.tsx b/packages/base-ui/src/views/components/doc-bars/Button/ToolbarButton.tsx
similarity index 100%
rename from packages/base-ui/src/views/components/DocBars/Button/ToolbarButton.tsx
rename to packages/base-ui/src/views/components/doc-bars/Button/ToolbarButton.tsx
diff --git a/packages/base-ui/src/views/components/DocBars/Button/index.module.less b/packages/base-ui/src/views/components/doc-bars/Button/index.module.less
similarity index 100%
rename from packages/base-ui/src/views/components/DocBars/Button/index.module.less
rename to packages/base-ui/src/views/components/doc-bars/Button/index.module.less
diff --git a/packages/base-ui/src/views/components/DocBars/DocBars.tsx b/packages/base-ui/src/views/components/doc-bars/DocBars.tsx
similarity index 100%
rename from packages/base-ui/src/views/components/DocBars/DocBars.tsx
rename to packages/base-ui/src/views/components/doc-bars/DocBars.tsx
diff --git a/packages/base-ui/src/views/components/DocBars/ToolbarItem.tsx b/packages/base-ui/src/views/components/doc-bars/ToolbarItem.tsx
similarity index 100%
rename from packages/base-ui/src/views/components/DocBars/ToolbarItem.tsx
rename to packages/base-ui/src/views/components/doc-bars/ToolbarItem.tsx
diff --git a/packages/base-ui/src/views/components/DocBars/index.module.less b/packages/base-ui/src/views/components/doc-bars/index.module.less
similarity index 100%
rename from packages/base-ui/src/views/components/DocBars/index.module.less
rename to packages/base-ui/src/views/components/doc-bars/index.module.less
diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts
index 875d71c12b..21a89f659a 100644
--- a/packages/design/src/index.ts
+++ b/packages/design/src/index.ts
@@ -4,6 +4,7 @@ export { Checkbox, type ICheckboxProps } from './components/checkbox';
export { CheckboxGroup, type ICheckboxGroupProps } from './components/checkbox-group';
export { ColorPicker, type IColorPickerProps } from './components/color-picker';
export { ConfigContext, ConfigProvider, type IConfigProviderProps } from './components/config-provider';
+export { Confirm, type IConfirmProps } from './components/confirm';
export { Container, type IContainerProps } from './components/container';
export { Dialog, type IDialogProps } from './components/dialog';
export { Dropdown, type IDropdownProps } from './components/dropdown';
diff --git a/packages/sheets-plugin-debugger/src/commands/operations/confirm.operation.ts b/packages/sheets-plugin-debugger/src/commands/operations/confirm.operation.ts
new file mode 100644
index 0000000000..6339e54226
--- /dev/null
+++ b/packages/sheets-plugin-debugger/src/commands/operations/confirm.operation.ts
@@ -0,0 +1,35 @@
+import { IConfirmService } from '@univerjs/base-ui';
+import { CommandType, ICommand } from '@univerjs/core';
+import { IAccessor } from '@wendellhu/redi';
+
+export interface IUIComponentCommandParams {
+ value: string;
+}
+
+export const ConfirmOperation: ICommand = {
+ id: 'debugger.operation.confirm',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor, params: IUIComponentCommandParams) => {
+ const confirmService = accessor.get(IConfirmService);
+
+ confirmService.open({
+ id: 'confirm1',
+ children: { title: 'Confirm Content' },
+ title: { title: 'Confirm Title' },
+ onClose() {
+ confirmService.close('confirm1');
+ },
+ });
+
+ confirmService.open({
+ id: 'confirm2',
+ children: { title: 'Confirm2 Content' },
+ title: { title: 'Confirm2 Title' },
+ onClose() {
+ confirmService.close('confirm2');
+ },
+ });
+
+ return true;
+ },
+};
diff --git a/packages/sheets-plugin-debugger/src/commands/operations/dialog.operation.ts b/packages/sheets-plugin-debugger/src/commands/operations/dialog.operation.ts
new file mode 100644
index 0000000000..2e2f1d7ef2
--- /dev/null
+++ b/packages/sheets-plugin-debugger/src/commands/operations/dialog.operation.ts
@@ -0,0 +1,39 @@
+import { IDialogService } from '@univerjs/base-ui';
+import { CommandType, ICommand } from '@univerjs/core';
+import { IAccessor } from '@wendellhu/redi';
+
+export interface IUIComponentCommandParams {
+ value: string;
+}
+
+export const DialogOperation: ICommand = {
+ id: 'debugger.operation.dialog',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor, params: IUIComponentCommandParams) => {
+ const dialogService = accessor.get(IDialogService);
+
+ dialogService.open({
+ id: 'dialog1',
+ children: { title: 'Dialog Content' },
+ footer: { title: 'Dialog Footer' },
+ title: { title: 'Dialog Title' },
+ draggable: false,
+ onClose() {
+ dialogService.close('dialog1');
+ },
+ });
+
+ dialogService.open({
+ id: 'dialog2',
+ children: { title: 'Dialog2 Content' },
+ footer: { title: 'Dialog2 Footer' },
+ title: { title: 'Dialog2 Title' },
+ draggable: true,
+ onClose() {
+ dialogService.close('dialog2');
+ },
+ });
+
+ return true;
+ },
+};
diff --git a/packages/sheets-plugin-debugger/src/commands/operations/locale.operation.ts b/packages/sheets-plugin-debugger/src/commands/operations/locale.operation.ts
index bf6321e19d..e2f2fe3c48 100644
--- a/packages/sheets-plugin-debugger/src/commands/operations/locale.operation.ts
+++ b/packages/sheets-plugin-debugger/src/commands/operations/locale.operation.ts
@@ -1,8 +1,6 @@
-import { CommandType, ICommand, LocaleType } from '@univerjs/core';
+import { CommandType, ICommand, LocaleService, LocaleType } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
-import { LocaleService } from '../../services/locale.service';
-
export interface ILocaleCommandParams {
value: LocaleType;
}
diff --git a/packages/sheets-plugin-debugger/src/commands/operations/ui-component.operation.ts b/packages/sheets-plugin-debugger/src/commands/operations/notification.operation.ts
similarity index 90%
rename from packages/sheets-plugin-debugger/src/commands/operations/ui-component.operation.ts
rename to packages/sheets-plugin-debugger/src/commands/operations/notification.operation.ts
index 6a13725f4e..89961e09c5 100644
--- a/packages/sheets-plugin-debugger/src/commands/operations/ui-component.operation.ts
+++ b/packages/sheets-plugin-debugger/src/commands/operations/notification.operation.ts
@@ -6,8 +6,8 @@ export interface IUIComponentCommandParams {
value: string;
}
-export const UIComponentOperation: ICommand = {
- id: 'debugger.operation.ui-component',
+export const NotificationOperation: ICommand = {
+ id: 'debugger.operation.notification',
type: CommandType.COMMAND,
handler: async (accessor: IAccessor, params: IUIComponentCommandParams) => {
const notificationService = accessor.get(INotificationService);
diff --git a/packages/sheets-plugin-debugger/src/commands/operations/theme.operation.ts b/packages/sheets-plugin-debugger/src/commands/operations/theme.operation.ts
index fef938d97d..ab9d6ca5db 100644
--- a/packages/sheets-plugin-debugger/src/commands/operations/theme.operation.ts
+++ b/packages/sheets-plugin-debugger/src/commands/operations/theme.operation.ts
@@ -1,8 +1,6 @@
-import { CommandType, ICommand, IStyleSheet } from '@univerjs/core';
+import { CommandType, ICommand, IStyleSheet, ThemeService } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
-import { ThemeService } from '../../services/theme.service';
-
export interface IThemeCommandParams {
value?: IStyleSheet;
}
diff --git a/packages/sheets-plugin-debugger/src/controllers/debugger.controller.ts b/packages/sheets-plugin-debugger/src/controllers/debugger.controller.ts
index 76e8debaa5..958e2c4a41 100644
--- a/packages/sheets-plugin-debugger/src/controllers/debugger.controller.ts
+++ b/packages/sheets-plugin-debugger/src/controllers/debugger.controller.ts
@@ -2,10 +2,18 @@ import { IMenuService } from '@univerjs/base-ui';
import { Disposable, ICommandService } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
+import { ConfirmOperation } from '../commands/operations/confirm.operation';
+import { DialogOperation } from '../commands/operations/dialog.operation';
import { LocaleOperation } from '../commands/operations/locale.operation';
+import { NotificationOperation } from '../commands/operations/notification.operation';
import { ThemeOperation } from '../commands/operations/theme.operation';
-import { UIComponentOperation } from '../commands/operations/ui-component.operation';
-import { LocaleMenuItemFactory, ThemeMenuItemFactory, UIComponentMenuItemFactory } from './menu';
+import {
+ ConfirmMenuItemFactory,
+ DialogMenuItemFactory,
+ LocaleMenuItemFactory,
+ NotificationMenuItemFactory,
+ ThemeMenuItemFactory,
+} from './menu';
export class DebuggerController extends Disposable {
constructor(
@@ -16,13 +24,19 @@ export class DebuggerController extends Disposable {
super();
this._initializeContextMenu();
- [LocaleOperation, ThemeOperation, UIComponentOperation].forEach((command) =>
+ [LocaleOperation, ThemeOperation, NotificationOperation, DialogOperation, ConfirmOperation].forEach((command) =>
this.disposeWithMe(this._commandService.registerCommand(command))
);
}
private _initializeContextMenu() {
- [LocaleMenuItemFactory, ThemeMenuItemFactory, UIComponentMenuItemFactory].forEach((factory) => {
+ [
+ LocaleMenuItemFactory,
+ ThemeMenuItemFactory,
+ NotificationMenuItemFactory,
+ DialogMenuItemFactory,
+ ConfirmMenuItemFactory,
+ ].forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
});
}
diff --git a/packages/sheets-plugin-debugger/src/controllers/menu.ts b/packages/sheets-plugin-debugger/src/controllers/menu.ts
index 9d47d26e69..3a9b86b7ff 100644
--- a/packages/sheets-plugin-debugger/src/controllers/menu.ts
+++ b/packages/sheets-plugin-debugger/src/controllers/menu.ts
@@ -3,9 +3,11 @@ import { LocaleType } from '@univerjs/core';
import { defaultTheme, greenTheme } from '@univerjs/design';
import { IAccessor } from '@wendellhu/redi';
+import { ConfirmOperation } from '../commands/operations/confirm.operation';
+import { DialogOperation } from '../commands/operations/dialog.operation';
import { LocaleOperation } from '../commands/operations/locale.operation';
+import { NotificationOperation } from '../commands/operations/notification.operation';
import { ThemeOperation } from '../commands/operations/theme.operation';
-import { UIComponentOperation } from '../commands/operations/ui-component.operation';
export function LocaleMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
return {
@@ -46,11 +48,12 @@ export function ThemeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
],
};
}
-export function UIComponentMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+
+export function NotificationMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
return {
- id: UIComponentOperation.id,
- title: 'debugger.uiComponent.title',
- tooltip: 'debugger.uiComponent.tooltip',
+ id: NotificationOperation.id,
+ title: 'debugger.notification.title',
+ tooltip: 'debugger.notification.tooltip',
type: MenuItemType.SELECTOR,
positions: [MenuPosition.TOOLBAR_OTHERS],
selections: [
@@ -73,3 +76,35 @@ export function UIComponentMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
],
};
}
+
+export function DialogMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+ return {
+ id: DialogOperation.id,
+ title: 'debugger.dialog.title',
+ tooltip: 'debugger.dialog.tooltip',
+ type: MenuItemType.SELECTOR,
+ positions: [MenuPosition.TOOLBAR_OTHERS],
+ selections: [
+ {
+ label: 'Open dialog',
+ value: 'dialog',
+ },
+ ],
+ };
+}
+
+export function ConfirmMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+ return {
+ id: ConfirmOperation.id,
+ title: 'debugger.confirm.title',
+ tooltip: 'debugger.confirm.tooltip',
+ type: MenuItemType.SELECTOR,
+ positions: [MenuPosition.TOOLBAR_OTHERS],
+ selections: [
+ {
+ label: 'Open confirm',
+ value: 'confirm',
+ },
+ ],
+ };
+}
diff --git a/packages/sheets-plugin-debugger/src/debugger-plugin.ts b/packages/sheets-plugin-debugger/src/debugger-plugin.ts
index f264022e50..d37aa5a3ee 100644
--- a/packages/sheets-plugin-debugger/src/debugger-plugin.ts
+++ b/packages/sheets-plugin-debugger/src/debugger-plugin.ts
@@ -3,8 +3,6 @@ import { Inject, Injector } from '@wendellhu/redi';
import { DebuggerController } from './controllers/debugger.controller';
import { enUS } from './locale';
-import { LocaleService } from './services/locale.service';
-import { ThemeService } from './services/theme.service';
export interface IDebuggerPluginConfig {}
@@ -28,8 +26,6 @@ export class DebuggerPlugin extends Plugin {
this._debuggerController = this._injector.createInstance(DebuggerController);
this._injector.add([DebuggerController, { useValue: this._debuggerController }]);
- this._injector.add([LocaleService]);
- this._injector.add([ThemeService]);
this.registerExtension();
}
diff --git a/packages/sheets-plugin-debugger/src/locale/en-US.ts b/packages/sheets-plugin-debugger/src/locale/en-US.ts
index d789bde2b4..2c8d4edb94 100644
--- a/packages/sheets-plugin-debugger/src/locale/en-US.ts
+++ b/packages/sheets-plugin-debugger/src/locale/en-US.ts
@@ -8,9 +8,17 @@ export default {
title: 'Theme',
tooltip: 'Theme',
},
- uiComponent: {
- title: 'UI Component',
- tooltip: 'UI Component',
+ notification: {
+ title: 'Notification',
+ tooltip: 'Notification',
+ },
+ dialog: {
+ title: 'Dialog',
+ tooltip: 'Dialog',
+ },
+ confirm: {
+ title: 'Confirm',
+ tooltip: 'Confirm',
},
},
};
diff --git a/packages/sheets-plugin-debugger/src/services/locale.service.ts b/packages/sheets-plugin-debugger/src/services/locale.service.ts
deleted file mode 100644
index c87693bc8f..0000000000
--- a/packages/sheets-plugin-debugger/src/services/locale.service.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { LocaleService as _LocaleService, LocaleType } from '@univerjs/core';
-import { Inject } from '@wendellhu/redi';
-
-export class LocaleService {
- constructor(@Inject(_LocaleService) private readonly _localeService: _LocaleService) {}
-
- setLocale(locale: LocaleType) {
- this._localeService.setLocale(locale);
- }
-}
diff --git a/packages/sheets-plugin-debugger/src/services/theme.service.ts b/packages/sheets-plugin-debugger/src/services/theme.service.ts
deleted file mode 100644
index 6d72d554d9..0000000000
--- a/packages/sheets-plugin-debugger/src/services/theme.service.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { IStyleSheet, ThemeService as _ThemeService } from '@univerjs/core';
-import { Inject } from '@wendellhu/redi';
-
-export class ThemeService {
- constructor(@Inject(_ThemeService) private readonly _themeService: _ThemeService) {}
-
- setTheme(theme: IStyleSheet) {
- this._themeService.setTheme(theme);
- }
-}