mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
feat(renderer): useExportSource hook (shared by export dialogs)
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
import { useFileStore } from '@/stores/file-store';
|
||||||
|
import { useEditorStore } from '@/stores/editor-store';
|
||||||
|
|
||||||
|
export interface ExportSource {
|
||||||
|
source: string;
|
||||||
|
path: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the active buffer's content from the editor store. Returns null if
|
||||||
|
* no buffer is open. Components handle the null case (prompt to open a file).
|
||||||
|
*/
|
||||||
|
export function useExportSource(): ExportSource | null {
|
||||||
|
const activeTabId = useFileStore((s) => s.activeTabId);
|
||||||
|
const openTabs = useFileStore((s) => s.openTabs);
|
||||||
|
const buffer = useEditorStore((s) => (activeTabId ? s.buffers.get(activeTabId) : undefined));
|
||||||
|
|
||||||
|
if (!activeTabId || !buffer) return null;
|
||||||
|
const tab = openTabs.find((t) => t.id === activeTabId);
|
||||||
|
return {
|
||||||
|
source: buffer.content,
|
||||||
|
path: activeTabId,
|
||||||
|
title: tab?.title ?? activeTabId,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user