feat(client): autoLayout add disableFitView option (#459)

This commit is contained in:
Louis Young 2025-07-04 11:17:08 +08:00 committed by GitHub
parent 4a857ba9a3
commit 1792e5f190
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 8 deletions

View File

@ -20,7 +20,11 @@ import { TransformData } from '@flowgram.ai/editor';
type AutoLayoutResetFn = () => void; type AutoLayoutResetFn = () => void;
type AutoLayoutFn = (options?: LayoutOptions) => Promise<AutoLayoutResetFn>; export type AutoLayoutOptions = LayoutOptions & {
disableFitView?: boolean;
};
type AutoLayoutFn = (options?: AutoLayoutOptions) => Promise<AutoLayoutResetFn>;
type UseAutoLayout = () => AutoLayoutFn; type UseAutoLayout = () => AutoLayoutFn;
@ -124,10 +128,15 @@ export const useAutoLayout: UseAutoLayout = () => {
[document, playground] [document, playground]
); );
const autoLayout: AutoLayoutFn = useCallback( const autoLayout: AutoLayoutFn = useCallback(
async (options?: LayoutOptions): Promise<AutoLayoutResetFn> => { async (options: AutoLayoutOptions = {}): Promise<AutoLayoutResetFn> => {
handleFitView(); const { disableFitView } = options;
if (disableFitView !== true) {
handleFitView();
}
const resetFn: AutoLayoutResetFn = await applyLayout(options); const resetFn: AutoLayoutResetFn = await applyLayout(options);
handleFitView(); if (disableFitView !== true) {
handleFitView();
}
return resetFn; return resetFn;
}, },
[applyLayout] [applyLayout]

View File

@ -16,10 +16,9 @@ import {
usePlayground, usePlayground,
useService, useService,
} from '@flowgram.ai/free-layout-core'; } from '@flowgram.ai/free-layout-core';
import { LayoutOptions } from '@flowgram.ai/free-auto-layout-plugin';
import { EditorState } from '@flowgram.ai/editor'; import { EditorState } from '@flowgram.ai/editor';
import { useAutoLayout } from './use-auto-layout'; import { useAutoLayout, type AutoLayoutOptions } from './use-auto-layout';
interface SetCursorStateCallbackEvent { interface SetCursorStateCallbackEvent {
isPressingSpaceBar: boolean; isPressingSpaceBar: boolean;
@ -31,7 +30,7 @@ export interface PlaygroundTools {
zoomin: (easing?: boolean) => void; zoomin: (easing?: boolean) => void;
zoomout: (easing?: boolean) => void; zoomout: (easing?: boolean) => void;
fitView: (easing?: boolean) => void; fitView: (easing?: boolean) => void;
autoLayout: (options?: LayoutOptions) => Promise<() => void>; autoLayout: (options?: AutoLayoutOptions) => Promise<() => void>;
/** /**
* 线 * 线
*/ */

View File

@ -71,7 +71,7 @@ export interface LayoutParams {
export interface LayoutOptions { export interface LayoutOptions {
getFollowNode?: GetFollowNode; getFollowNode?: GetFollowNode;
enableAnimation: boolean; enableAnimation?: boolean;
} }
export interface LayoutConfig { export interface LayoutConfig {