From 54998d5c1bab3a49c336212a731d15a841a8a4ae Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Sun, 13 Apr 2025 11:53:06 +0800 Subject: [PATCH] feat(dockview): update DockView component to support external onApiReady callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Removed the internal use of `useDockviewStore` for managing Dockview API state. - Introduced `onApiReady` prop to allow external handling of the `DockviewApi` when it’s ready. - Updated `onReady` function to invoke `onApiReady` callback with the API instance. - Ensured backward compatibility by keeping the previous internal handling of `DockviewApi`. --- src/components/dockview.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/dockview.tsx b/src/components/dockview.tsx index 2c63cd1..83508da 100644 --- a/src/components/dockview.tsx +++ b/src/components/dockview.tsx @@ -9,7 +9,6 @@ import type { } from "dockview"; import "@/styles/dockview.css"; import type { LucideIcon } from "lucide-react"; -import { useDockviewStore } from "@/stores/dockview"; import { useEffect, useMemo, useState } from "react"; import { DockviewReact, themeAbyssSpaced } from "dockview"; @@ -21,11 +20,11 @@ interface PanelContent { interface DockviewProps { storageKey: string; + onApiReady?: (api: DockviewApi) => void; options: AddPanelOptions[]; } -export default function DockView({ storageKey, options }: DockviewProps) { - const { setApi: _setApi } = useDockviewStore(); +export default function DockView({ storageKey, onApiReady, options }: DockviewProps) { const [api, setApi] = useState(); const { components, tabComponents } = useMemo(() => { @@ -79,7 +78,7 @@ export default function DockView({ storageKey, options }: DockviewProps) { const onReady = (event: DockviewReadyEvent) => { setApi(event.api); - _setApi(event.api); + onApiReady?.(event.api); let success = false; const serializedLayout = localStorage.getItem(storageKey);