feat: add dom update methods
This commit is contained in:
@@ -27,6 +27,41 @@ interface ScheduleConfig {
|
|||||||
cronExpression?: string;
|
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 {
|
export interface RobotSettings {
|
||||||
id: string;
|
id: string;
|
||||||
userId?: number;
|
userId?: number;
|
||||||
@@ -86,6 +121,11 @@ interface GlobalInfo {
|
|||||||
setCurrentListActionId: (actionId: string) => void;
|
setCurrentListActionId: (actionId: string) => void;
|
||||||
currentScreenshotActionId: string;
|
currentScreenshotActionId: string;
|
||||||
setCurrentScreenshotActionId: (actionId: string) => void;
|
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<GlobalInfo> {
|
class GlobalInfoStore implements Partial<GlobalInfo> {
|
||||||
@@ -115,6 +155,8 @@ class GlobalInfoStore implements Partial<GlobalInfo> {
|
|||||||
currentTextActionId = '';
|
currentTextActionId = '';
|
||||||
currentListActionId = '';
|
currentListActionId = '';
|
||||||
currentScreenshotActionId = '';
|
currentScreenshotActionId = '';
|
||||||
|
isDOMMode = false;
|
||||||
|
currentSnapshot = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const globalInfoStore = new GlobalInfoStore();
|
const globalInfoStore = new GlobalInfoStore();
|
||||||
@@ -141,6 +183,8 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
|
|||||||
const [currentTextActionId, setCurrentTextActionId] = useState<string>('');
|
const [currentTextActionId, setCurrentTextActionId] = useState<string>('');
|
||||||
const [currentListActionId, setCurrentListActionId] = useState<string>('');
|
const [currentListActionId, setCurrentListActionId] = useState<string>('');
|
||||||
const [currentScreenshotActionId, setCurrentScreenshotActionId] = useState<string>('');
|
const [currentScreenshotActionId, setCurrentScreenshotActionId] = useState<string>('');
|
||||||
|
const [isDOMMode, setIsDOMMode] = useState<boolean>(globalInfoStore.isDOMMode);
|
||||||
|
const [currentSnapshot, setCurrentSnapshot] = useState<ProcessedSnapshot | null>(globalInfoStore.currentSnapshot);
|
||||||
|
|
||||||
const notify = (severity: 'error' | 'warning' | 'info' | 'success', message: string) => {
|
const notify = (severity: 'error' | 'warning' | 'info' | 'success', message: string) => {
|
||||||
setNotification({ severity, message, isOpen: true });
|
setNotification({ severity, message, isOpen: true });
|
||||||
@@ -165,6 +209,18 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
|
|||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateDOMMode = (mode: boolean, snapshot?: ProcessedSnapshot | null) => {
|
||||||
|
setIsDOMMode(mode);
|
||||||
|
|
||||||
|
if (snapshot !== undefined) {
|
||||||
|
setCurrentSnapshot(snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mode) {
|
||||||
|
setCurrentSnapshot(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<globalInfoContext.Provider
|
<globalInfoContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@@ -205,6 +261,11 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
|
|||||||
setCurrentListActionId,
|
setCurrentListActionId,
|
||||||
currentScreenshotActionId,
|
currentScreenshotActionId,
|
||||||
setCurrentScreenshotActionId,
|
setCurrentScreenshotActionId,
|
||||||
|
isDOMMode,
|
||||||
|
setIsDOMMode,
|
||||||
|
currentSnapshot,
|
||||||
|
setCurrentSnapshot,
|
||||||
|
updateDOMMode,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Reference in New Issue
Block a user