From f21ad1ec02f0fca99c7acd61a3c81b9b4a359968 Mon Sep 17 00:00:00 2001 From: Rohit Date: Sun, 6 Jul 2025 21:47:24 +0530 Subject: [PATCH] feat: add dom update methods --- src/context/globalInfo.tsx | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/context/globalInfo.tsx b/src/context/globalInfo.tsx index 55f96b06..6f3cf8cd 100644 --- a/src/context/globalInfo.tsx +++ b/src/context/globalInfo.tsx @@ -27,6 +27,41 @@ interface ScheduleConfig { cronExpression?: string; } +interface ProcessedSnapshot { + snapshot: any; + resources: { + stylesheets: Array<{ + href: string; + content: string; + media?: string; + }>; + images: Array<{ + src: string; + dataUrl: string; + alt?: string; + }>; + fonts: Array<{ + url: string; + dataUrl: string; + format?: string; + }>; + scripts: Array<{ + src: string; + content: string; + type?: string; + }>; + media: Array<{ + src: string; + dataUrl: string; + type: string; + }>; + }; + baseUrl: string; + viewport: { width: number; height: number }; + timestamp: number; + processingStats: any; +} + export interface RobotSettings { id: string; userId?: number; @@ -86,6 +121,11 @@ interface GlobalInfo { setCurrentListActionId: (actionId: string) => void; currentScreenshotActionId: string; setCurrentScreenshotActionId: (actionId: string) => void; + isDOMMode: boolean; + setIsDOMMode: (isDOMMode: boolean) => void; + currentSnapshot: ProcessedSnapshot | null; + setCurrentSnapshot: (snapshot: ProcessedSnapshot | null) => void; + updateDOMMode: (isDOMMode: boolean, snapshot?: ProcessedSnapshot | null) => void; }; class GlobalInfoStore implements Partial { @@ -115,6 +155,8 @@ class GlobalInfoStore implements Partial { currentTextActionId = ''; currentListActionId = ''; currentScreenshotActionId = ''; + isDOMMode = false; + currentSnapshot = null; }; const globalInfoStore = new GlobalInfoStore(); @@ -141,6 +183,8 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { const [currentTextActionId, setCurrentTextActionId] = useState(''); const [currentListActionId, setCurrentListActionId] = useState(''); const [currentScreenshotActionId, setCurrentScreenshotActionId] = useState(''); + const [isDOMMode, setIsDOMMode] = useState(globalInfoStore.isDOMMode); + const [currentSnapshot, setCurrentSnapshot] = useState(globalInfoStore.currentSnapshot); const notify = (severity: 'error' | 'warning' | 'info' | 'success', message: string) => { setNotification({ severity, message, isOpen: true }); @@ -165,6 +209,18 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { }, 100); } + const updateDOMMode = (mode: boolean, snapshot?: ProcessedSnapshot | null) => { + setIsDOMMode(mode); + + if (snapshot !== undefined) { + setCurrentSnapshot(snapshot); + } + + if (!mode) { + setCurrentSnapshot(null); + } + } + return ( { setCurrentListActionId, currentScreenshotActionId, setCurrentScreenshotActionId, + isDOMMode, + setIsDOMMode, + currentSnapshot, + setCurrentSnapshot, + updateDOMMode, }} > {children}