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): add `preservePositionOnDestroy` & `defaultPosition` to Dialog (#1439)
白熱b1d18cae4ed3
diff --git a/.github/workflows/preview-deploy.yml b/.github/workflows/preview-deploy.ymlindex b7407da103..57d0c462b6 100644--- a/.github/workflows/preview-deploy.yml+++ b/.github/workflows/preview-deploy.yml@@ -145,7 +145,7 @@ jobs:needs: [setup]outputs:- preview-url: ${{ steps.vercel-storybook.outputs.preview-url }}+ preview-url: ${{ steps.vercel-storybook-dev.outputs.preview-url == '' && steps.vercel-storybook.outputs.preview-url || steps.vercel-storybook-dev.outputs.preview-url }}steps:- name: Checkoutdiff --git a/.vscode/extensions.json b/.vscode/extensions.jsonindex 8bc6ff24c6..a0b02c08ec 100644--- a/.vscode/extensions.json+++ b/.vscode/extensions.json@@ -8,7 +8,6 @@"streetsidesoftware.code-spell-checker","tldraw-org.tldraw-vscode","kingwl.vscode-vitest-runner",- "usernamehw.errorlens",- "hoodiecollin.es6-string-typescript"+ "usernamehw.errorlens"]}diff --git a/examples/src/plugins/debugger/commands/operations/dialog.operation.ts b/examples/src/plugins/debugger/commands/operations/dialog.operation.tsindex 8a506b7fc5..4ed82a4f9e 100644--- a/examples/src/plugins/debugger/commands/operations/dialog.operation.ts+++ b/examples/src/plugins/debugger/commands/operations/dialog.operation.ts@@ -36,6 +36,8 @@ export const DialogOperation: ICommand = {children: { title: 'Draggable Dialog Content' },title: { title: 'Draggable Dialog' },draggable: true,+ destroyOnClose: true,+ preservePositionOnDestroy: true,width: 350,onClose() {dialogService.close('draggable');diff --git a/packages/design/src/components/dialog/Dialog.stories.tsx b/packages/design/src/components/dialog/Dialog.stories.tsxindex 559f6ae42e..96349d0683 100644--- a/packages/design/src/components/dialog/Dialog.stories.tsx+++ b/packages/design/src/components/dialog/Dialog.stories.tsx@@ -46,7 +46,6 @@ export const DialogBasic = {<Dialogvisible={visible}title="hello world"- draggablecloseIcon={<CloseSingle />}footer={<footer>footer</footer>}onClose={handleToggleVisible}@@ -57,3 +56,31 @@ export const DialogBasic = {);},};++export const DialogDraggable = {+ render() {+ const [visible, setVisible] = useState(false);++ function handleToggleVisible() {+ setVisible(!visible);+ }++ return (+ <>+ <Button onClick={handleToggleVisible}>open dialog</Button>+ <Dialog+ visible={visible}+ title="hello world"+ closeIcon={<CloseSingle />}+ draggable+ destroyOnClose+ preservePositionOnDestroy+ defaultPosition={{ x: 100, y: 100 }}+ onClose={handleToggleVisible}+ >+ xxxx+ </Dialog>+ </>+ );+ },+};diff --git a/packages/design/src/components/dialog/Dialog.tsx b/packages/design/src/components/dialog/Dialog.tsxindex ce6c644327..b023c9c258 100644--- a/packages/design/src/components/dialog/Dialog.tsx+++ b/packages/design/src/components/dialog/Dialog.tsx@@ -17,6 +17,7 @@import { CloseSingle } from '@univerjs/icons';import RcDialog from 'rc-dialog';import React, { useContext, useState } from 'react';+import type { DraggableData, DraggableEventHandler } from 'react-draggable';import Draggable from 'react-draggable';import { ConfigContext } from '../config-provider/ConfigProvider';@@ -59,12 +60,23 @@ export interface IDialogProps {*/closeIcon?: React.ReactNode;+ /**+ * The default position of the dialog.+ */+ defaultPosition?: { x: number; y: number };+/*** Whether the dialog should be destroyed on close.* @default false*/destroyOnClose?: boolean;+ /**+ * Whether the dialog should preserve its position on destroy.+ * @default false+ */+ preservePositionOnDestroy?: boolean;+/*** The footer of the dialog.*/@@ -85,11 +97,14 @@ export function Dialog(props: IDialogProps) {width,draggable = false,closeIcon = <CloseSingle />,+ defaultPosition,destroyOnClose = false,+ preservePositionOnDestroy = false,footer,onClose,} = props;const [dragDisabled, setDragDisabled] = useState(false);+ const [positionOffset, setPositionOffset] = useState<{ x: number; y: number } | null>(null);const { mountContainer } = useContext(ConfigContext);@@ -118,8 +133,27 @@ export function Dialog(props: IDialogProps) {title);- const modalRender = (modal: React.ReactNode) =>- draggable ? <Draggable disabled={dragDisabled}>{modal}</Draggable> : modal;+ const modalRender = (modal: React.ReactNode) => {+ function handleStop(_event: MouseEvent, data: DraggableData) {+ if (preservePositionOnDestroy) {+ setPositionOffset({ x: data.x, y: data.y });+ }+ }++ const position = positionOffset || defaultPosition || { x: 0, y: 0 };++ return draggable+ ? (+ <Draggable+ disabled={dragDisabled}+ defaultPosition={position}+ onStop={handleStop as DraggableEventHandler}+ >+ {modal}+ </Draggable>+ )+ : modal;+ };return (<RcDialog