Skip to content

Commit f21ad1e

Browse files
committed
feat: add dom update methods
1 parent 330997f commit f21ad1e

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/context/globalInfo.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,41 @@ interface ScheduleConfig {
2727
cronExpression?: string;
2828
}
2929

30+
interface ProcessedSnapshot {
31+
snapshot: any;
32+
resources: {
33+
stylesheets: Array<{
34+
href: string;
35+
content: string;
36+
media?: string;
37+
}>;
38+
images: Array<{
39+
src: string;
40+
dataUrl: string;
41+
alt?: string;
42+
}>;
43+
fonts: Array<{
44+
url: string;
45+
dataUrl: string;
46+
format?: string;
47+
}>;
48+
scripts: Array<{
49+
src: string;
50+
content: string;
51+
type?: string;
52+
}>;
53+
media: Array<{
54+
src: string;
55+
dataUrl: string;
56+
type: string;
57+
}>;
58+
};
59+
baseUrl: string;
60+
viewport: { width: number; height: number };
61+
timestamp: number;
62+
processingStats: any;
63+
}
64+
3065
export interface RobotSettings {
3166
id: string;
3267
userId?: number;
@@ -86,6 +121,11 @@ interface GlobalInfo {
86121
setCurrentListActionId: (actionId: string) => void;
87122
currentScreenshotActionId: string;
88123
setCurrentScreenshotActionId: (actionId: string) => void;
124+
isDOMMode: boolean;
125+
setIsDOMMode: (isDOMMode: boolean) => void;
126+
currentSnapshot: ProcessedSnapshot | null;
127+
setCurrentSnapshot: (snapshot: ProcessedSnapshot | null) => void;
128+
updateDOMMode: (isDOMMode: boolean, snapshot?: ProcessedSnapshot | null) => void;
89129
};
90130

91131
class GlobalInfoStore implements Partial<GlobalInfo> {
@@ -115,6 +155,8 @@ class GlobalInfoStore implements Partial<GlobalInfo> {
115155
currentTextActionId = '';
116156
currentListActionId = '';
117157
currentScreenshotActionId = '';
158+
isDOMMode = false;
159+
currentSnapshot = null;
118160
};
119161

120162
const globalInfoStore = new GlobalInfoStore();
@@ -141,6 +183,8 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
141183
const [currentTextActionId, setCurrentTextActionId] = useState<string>('');
142184
const [currentListActionId, setCurrentListActionId] = useState<string>('');
143185
const [currentScreenshotActionId, setCurrentScreenshotActionId] = useState<string>('');
186+
const [isDOMMode, setIsDOMMode] = useState<boolean>(globalInfoStore.isDOMMode);
187+
const [currentSnapshot, setCurrentSnapshot] = useState<ProcessedSnapshot | null>(globalInfoStore.currentSnapshot);
144188

145189
const notify = (severity: 'error' | 'warning' | 'info' | 'success', message: string) => {
146190
setNotification({ severity, message, isOpen: true });
@@ -165,6 +209,18 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
165209
}, 100);
166210
}
167211

212+
const updateDOMMode = (mode: boolean, snapshot?: ProcessedSnapshot | null) => {
213+
setIsDOMMode(mode);
214+
215+
if (snapshot !== undefined) {
216+
setCurrentSnapshot(snapshot);
217+
}
218+
219+
if (!mode) {
220+
setCurrentSnapshot(null);
221+
}
222+
}
223+
168224
return (
169225
<globalInfoContext.Provider
170226
value={{
@@ -205,6 +261,11 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
205261
setCurrentListActionId,
206262
currentScreenshotActionId,
207263
setCurrentScreenshotActionId,
264+
isDOMMode,
265+
setIsDOMMode,
266+
currentSnapshot,
267+
setCurrentSnapshot,
268+
updateDOMMode,
208269
}}
209270
>
210271
{children}

0 commit comments

Comments
 (0)