Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(design): polish draggable dialog (#1106)
Wenzhao Hu3ea86aa3847a
diff --git a/examples/src/plugins/debugger/commands/operations/dialog.operation.ts b/examples/src/plugins/debugger/commands/operations/dialog.operation.tsindex 7f3a0be5bf..0e8ddd9150 100644--- a/examples/src/plugins/debugger/commands/operations/dialog.operation.ts+++ b/examples/src/plugins/debugger/commands/operations/dialog.operation.ts@@ -28,28 +28,30 @@ export const DialogOperation: ICommand = {type: CommandType.COMMAND,handler: async (accessor: IAccessor, params: IUIComponentCommandParams) => {const dialogService = accessor.get(IDialogService);+ const { value } = params;- 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');- },- });+ if (value === 'draggable') {+ dialogService.open({+ id: 'draggable',+ children: { title: 'Draggable Dialog Content' },+ title: { title: 'Draggable Dialog' },+ draggable: true,+ onClose() {+ dialogService.close('draggable');+ },+ });+ } else {+ dialogService.open({+ id: 'dialog1',+ children: { title: 'Dialog Content' },+ footer: { title: 'Dialog Footer' },+ title: { title: 'Dialog Title' },+ draggable: false,+ onClose() {+ dialogService.close('dialog1');+ },+ });+ }return true;},diff --git a/examples/src/plugins/debugger/controllers/menu.ts b/examples/src/plugins/debugger/controllers/menu.tsindex d8f42fe2c3..be5e96221d 100644--- a/examples/src/plugins/debugger/controllers/menu.ts+++ b/examples/src/plugins/debugger/controllers/menu.ts@@ -107,9 +107,13 @@ export function DialogMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {positions: [MenuPosition.TOOLBAR_OTHERS],selections: [{- label: 'Open dialog',+ label: 'Open Dialog',value: 'dialog',},+ {+ label: 'Draggable Dialog',+ value: 'draggable',+ },],};}diff --git a/packages/design/src/components/dialog/Dialog.tsx b/packages/design/src/components/dialog/Dialog.tsxindex 64053a4a6a..d4563c8d9a 100644--- a/packages/design/src/components/dialog/Dialog.tsx+++ b/packages/design/src/components/dialog/Dialog.tsx@@ -14,6 +14,7 @@* limitations under the License.*/+import { CloseSingle } from '@univerjs/icons';import RcDialog from 'rc-dialog';import React, { useContext, useState } from 'react';import Draggable from 'react-draggable';@@ -36,7 +37,9 @@ export interface IDialogProps {title?: React.ReactNode;/**- * Whether the dialog can be dragged.+ * Whether the dialog can be dragged. If a dialog is draggable, the backdrop would be hidden and+ * the wrapper container would not response to user's mouse events.+ ** @default false*/draggable?: boolean;@@ -58,7 +61,7 @@ export interface IDialogProps {}export function Dialog(props: IDialogProps) {- const { children, visible = false, title, draggable = false, closeIcon, footer, onClose } = props;+ const { children, visible = false, title, draggable = false, closeIcon = <CloseSingle />, footer, onClose } = props;const [dragDisabled, setDragDisabled] = useState(false);const { mountContainer } = useContext(ConfigContext);@@ -92,6 +95,7 @@ export function Dialog(props: IDialogProps) {return (<RcDialogprefixCls={styles.dialog}+ rootClassName={draggable ? styles.dialogRootDraggable : styles.dialogRoot}getContainer={() => mountContainer}visible={visible}title={TitleIfDraggable}@@ -99,6 +103,7 @@ export function Dialog(props: IDialogProps) {closeIcon={closeIcon}footer={footer}onClose={onClose}+ mask={!draggable}>{children}</RcDialog>diff --git a/packages/design/src/components/dialog/index.module.less b/packages/design/src/components/dialog/index.module.lessindex cb30b75872..85f6c11bad 100644--- a/packages/design/src/components/dialog/index.module.less+++ b/packages/design/src/components/dialog/index.module.less@@ -22,6 +22,8 @@}&-content {+ pointer-events: all;+position: relative;color: rgb(var(--text-color));@@ -42,10 +44,10 @@padding: 0;- font-size: var(--font-size-base);+ font-size: var(--font-size-lg);font-weight: 500;line-height: 1;- color: rgb(var(--text-color));+ color: rgb(var(--grey-500));text-decoration: none;opacity: .2;@@ -189,4 +191,8 @@opacity: 0;}}++ &-root-draggable {+ pointer-events: none;+ }}diff --git a/packages/ui/src/services/dialog/desktop-dialog.service.ts b/packages/ui/src/services/dialog/desktop-dialog.service.tsindex 77d8fc7120..94f4f6378a 100644--- a/packages/ui/src/services/dialog/desktop-dialog.service.ts+++ b/packages/ui/src/services/dialog/desktop-dialog.service.ts@@ -14,47 +14,54 @@* limitations under the License.*/-import { toDisposable } from '@univerjs/core';+import { Disposable, toDisposable } from '@univerjs/core';import type { IDisposable } from '@wendellhu/redi';import { Subject } from 'rxjs';import { type IDialogPartMethodOptions } from '../../views/components/dialog-part/interface';import type { IDialogService } from './dialog.service';-export class DesktopDialogService implements IDialogService {- private dialogOptions: IDialogPartMethodOptions[] = [];- private readonly dialogOptions$ = new Subject<IDialogPartMethodOptions[]>();+export class DesktopDialogService extends Disposable implements IDialogService {+ private _dialogOptions: IDialogPartMethodOptions[] = [];+ private readonly _dialogOptions$ = new Subject<IDialogPartMethodOptions[]>();++ override dispose(): void {+ super.dispose();++ this._dialogOptions$.complete();+ }open(option: IDialogPartMethodOptions): IDisposable {- if (this.dialogOptions.find((item) => item.id === option.id)) {- this.dialogOptions = this.dialogOptions.map((item) => ({+ 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({+ this._dialogOptions.push({...option,visible: true,});}- this.dialogOptions$.next(this.dialogOptions);+ this._dialogOptions$.next(this._dialogOptions);return toDisposable(() => {- this.dialogOptions = [];- this.dialogOptions$.next([]);+ this._dialogOptions = [];+ this._dialogOptions$.next([]);});}close(id: string) {- this.dialogOptions = this.dialogOptions.map((item) => ({+ this._dialogOptions = this._dialogOptions.map((item) => ({...item,visible: item.id === id ? false : item.visible,}));- this.dialogOptions$.next([...this.dialogOptions]);++ this._dialogOptions$.next([...this._dialogOptions]);}getObservableDialog() {- return this.dialogOptions$;+ return this._dialogOptions$;}}diff --git a/packages/ui/src/services/dialog/dialog.service.ts b/packages/ui/src/services/dialog/dialog.service.tsindex ef8e927ee1..24bc09b92b 100644--- a/packages/ui/src/services/dialog/dialog.service.ts+++ b/packages/ui/src/services/dialog/dialog.service.ts@@ -21,11 +21,8 @@ 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[]>;}